package com.ruoyi.surfacewater.service.impl;

import com.ruoyi.base.mapper.PublicToolsMapper;
import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.surfacewater.mapper.BusMonthlycumulativedataMapper;
import com.ruoyi.surfacewater.mapper.ManualComparisonOfWaterQualityMapper;
import com.ruoyi.surfacewater.service.ExcellentAndUpToStandardUtliService;
import com.ruoyi.utli.SegmentFormula;
import com.ruoyi.utli.mapper.RegionUtliMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class ExcellentAndUpToStandardUtliServiceImpl implements ExcellentAndUpToStandardUtliService {
    @Autowired
    private SegmentFormula segmentFormula;
    @Autowired
    private RuoYiConfig ruoYiConfig;
    @Autowired
    private PublicToolsMapper publicToolsMapper;
    @Autowired
    private ManualComparisonOfWaterQualityMapper  manualComparisonOfWaterQualityMapper;
    @Autowired
    private RegionUtliMapper regionUtliMapper;
    @Autowired
    private BusMonthlycumulativedataMapper busMonthlycumulativedataMapper;

    @Override
    public Map<String, Object> countySectionWaterQualityIndex(Map<String, Object> map) {
        DecimalFormat format2 = new DecimalFormat("0.00");
        //水质等级传一查询出修约需要的数据
        List<Map<String, Object>> hlroundingOffmaps = segmentFormula.wqBasStandardcategory("1", "1");
        //水质等级为三查询出水质指数计算的数据
        List<Map<String, Object>> hlindexmaps = segmentFormula.wqBasStandardcategory("1", "3");
        //水质等级传一查询出修约需要的数据
        List<Map<String, Object>> hkroundingOffmaps = segmentFormula.wqBasStandardcategory("2", "1");
        //水质等级为三查询出水质指数计算的数据
        List<Map<String, Object>> hkindexmaps = segmentFormula.wqBasStandardcategory("2", "3");
        Map<String, Object> mapdata = new HashMap<>();//存放返回数据
        //湖库/河流对应断面idid
        List<String> cityCodes = (List<String>) map.get("CityCodes");//区划
        List<String> monthall = (List<String>) map.get("monthall");//开始时间
        List<Map<String, Object>> ItemIsRiverEvalute = (List<Map<String, Object>>) map.get("ItemIsRiverEvalute");//参与计算因子
        Object whetherYOY = map.get("whetherYOY");//是否展示同比
        Object type = map.get("type");//不为空的话返回所有年份的总均值然后计算总体水质指数
        List<String> tbmonthall = (List<String>) map.get("tbmonthall");
        //对应监测数据均值 同比/当前
        List<Map<String, Object>> hkdata = (List<Map<String, Object>>) map.get("hkdata");
        List<Map<String, Object>> hldata = (List<Map<String, Object>>) map.get("hldata");
        List<Map<String, Object>> tbhkdata = (List<Map<String, Object>>) map.get("tbhkmaps");
        List<Map<String, Object>> tbhldata = (List<Map<String, Object>>) map.get("tbhlmaps");
        //累计需要计算的数据
        List<Map<String, Object>> ljhkdata = (List<Map<String, Object>>) map.get("ljhkdata");
        List<Map<String, Object>> ljhldata = (List<Map<String, Object>>) map.get("ljhldata");
        List<Map<String, Object>> ljtbhkdata = (List<Map<String, Object>>) map.get("ljtbhkmaps");
        List<Map<String, Object>> ljtbhldata = (List<Map<String, Object>>) map.get("ljtbhlmaps");
        //获取对应id的每个区划不通数据类型的数量
        List<Map<String, Object>> segmentCountysl = (List<Map<String, Object>>) map.get("segmentCountysl");
        List<Map<String, Object>> tbsegmentCountysl = (List<Map<String, Object>>) map.get("tbsegmentCountysl");
        //分组判断，stream流
        Map<String, List<Map<String, Object>>> hkCountyCodedata =
                hkdata.stream().collect(
                        Collectors.groupingBy(item -> item.get("CountyCode").toString())
                );
        Map<String, List<Map<String, Object>>> hlCountyCodedata =
                hldata.stream().collect(
                        Collectors.groupingBy(item -> item.get("CountyCode").toString())
                );
        //累计计算断面
        Map<String, List<Map<String, Object>>> ljhkCountyCodedata =
                ljhkdata.stream().collect(
                        Collectors.groupingBy(item -> item.get("CountyCode").toString())
                );
        Map<String, List<Map<String, Object>>> ljhlCountyCodedata =
                ljhldata.stream().collect(
                        Collectors.groupingBy(item -> item.get("CountyCode").toString())
                );
        Map<String, List<Map<String, Object>>> tbhkCountyCodedata = new HashMap<>();
        Map<String, List<Map<String, Object>>> tbhlCountyCodedata = new HashMap<>();
        Map<String, List<Map<String, Object>>> ljtbhkCountyCodedata = new HashMap<>();
        Map<String, List<Map<String, Object>>> ljtbhlCountyCodedata = new HashMap<>();
        //if (whetherYOY != null && whetherYOY.equals("1")) {
        tbhkCountyCodedata =
                tbhkdata.stream().collect(
                        Collectors.groupingBy(item -> item.get("CountyCode").toString())
                );
        tbhlCountyCodedata =
                tbhldata.stream().collect(
                        Collectors.groupingBy(item -> item.get("CountyCode").toString())
                );
        ljtbhkCountyCodedata =
                ljtbhkdata.stream().collect(
                        Collectors.groupingBy(item -> item.get("CountyCode").toString())
                );
        ljtbhlCountyCodedata =
                ljtbhldata.stream().collect(
                        Collectors.groupingBy(item -> item.get("CountyCode").toString())
                );
        //}
        List<Map<String, Object>> maplist = new ArrayList<>();
        //先判断传入的区划为空吗
        if (cityCodes != null && cityCodes.size() > 0) {
            for (String codedata : cityCodes) {
                Map<String, Object> segmentdatamap = new HashMap<>();
                segmentdatamap.put("countyCode", codedata);
                //分组查询湖库和河流 （当前区划下的数据）
                List<Map<String, Object>> hkCountyCodedatamaps = hkCountyCodedata.get(codedata);
                List<Map<String, Object>> hlCountyCodedatamaps = hlCountyCodedata.get(codedata);
                //tb分组查询湖库和河流 （当前区划下的数据）
                List<Map<String, Object>> tbhkCountyCodedatamaps = tbhkCountyCodedata.get(codedata);
                List<Map<String, Object>> tbhlCountyCodedatamaps = tbhlCountyCodedata.get(codedata);
                //分组查询湖库和河流 （当前区划下的数据）
                List<Map<String, Object>> ljhkCountyCodedatamaps = ljhkCountyCodedata.get(codedata);
                List<Map<String, Object>> ljhlCountyCodedatamaps = ljhlCountyCodedata.get(codedata);
                //tb分组查询湖库和河流 （当前区划下的数据）
                List<Map<String, Object>> ljtbhkCountyCodedatamaps = ljtbhkCountyCodedata.get(codedata);
                List<Map<String, Object>> ljtbhlCountyCodedatamaps = ljtbhlCountyCodedata.get(codedata);
                //根据对应区划处理对应断面id 得到断面id 和断面id数量
                int hksize = 0;
                int hlsize = 0;
                int tbhksize = 0;
                int tbhlsize = 0;
                if (segmentCountysl != null && segmentCountysl.size() > 0) {
                    for (Map<String, Object> datasl : segmentCountysl) {
                        Object sl = datasl.get("sl");//数量
                        Object countyCode = datasl.get("CountyCode");//区划编码
                        Object segmentCategory = datasl.get("SegmentCategory");//断面类型 1是河流 2湖库
                        Object county = datasl.get("County");//区划名称
                        if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                            if (countyCode != null && countyCode.equals(codedata)) {
                                if (hlsize < Integer.valueOf(String.valueOf(sl))) {
                                    hlsize = Integer.valueOf(String.valueOf(sl));
                                }

                            }
                        }
                        if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                            if (countyCode != null && countyCode.equals(codedata)) {
                                if (hksize < Integer.valueOf(String.valueOf(sl))) {
                                    hksize = Integer.valueOf(String.valueOf(sl));
                                }

                            }
                        }
                    }

                }
                if (tbsegmentCountysl != null && tbsegmentCountysl.size() > 0) {
                    for (Map<String, Object> datasl : tbsegmentCountysl) {
                        Object sl = datasl.get("sl");//数量
                        Object countyCode = datasl.get("CountyCode");//区划编码
                        Object segmentCategory = datasl.get("SegmentCategory");//断面类型 1是河流 2湖库
                        Object county = datasl.get("County");//区划名称
                        if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                            if (countyCode != null && countyCode.equals(codedata)) {
                                if (tbhlsize < Integer.valueOf(String.valueOf(sl))) {
                                    tbhlsize = Integer.valueOf(String.valueOf(sl));
                                }

                            }
                        }
                        if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                            if (countyCode != null && countyCode.equals(codedata)) {
                                if (tbhksize < Integer.valueOf(String.valueOf(sl))) {
                                    tbhksize = Integer.valueOf(String.valueOf(sl));
                                }

                            }
                        }
                    }

                }


                if (type != null && !"".equals(type)) {
                    if (ItemIsRiverEvalute != null && ItemIsRiverEvalute.size() > 0) {
                        Map<String, List<Map<String, Object>>> hkitemdata = new HashMap<>();
                        if (ljhkCountyCodedatamaps != null && ljhkCountyCodedatamaps.size() > 0) {
                            hkitemdata =
                                    ljhkCountyCodedatamaps.stream().collect(
                                            Collectors.groupingBy(item -> item.get("ItemCode").toString())
                                    );
                        }
                        //分组判断，stream流
                        Map<String, List<Map<String, Object>>> hlitemdata = new HashMap<>();
                        if (ljhlCountyCodedatamaps != null && ljhlCountyCodedatamaps.size() > 0) {
                            hlitemdata =
                                    ljhlCountyCodedatamaps.stream().collect(
                                            Collectors.groupingBy(item -> item.get("ItemCode").toString())
                                    );
                        }

                        Map<String, List<Map<String, Object>>> tbhkitemdata = new HashMap<>();
                        if (ljtbhkCountyCodedatamaps != null && ljtbhkCountyCodedatamaps.size() > 0) {
                            tbhkitemdata =
                                    ljtbhkCountyCodedatamaps.stream().collect(
                                            Collectors.groupingBy(item -> item.get("ItemCode").toString())
                                    );
                        }
                        Map<String, List<Map<String, Object>>> tbhlitemdata = new HashMap<>();
                        if (ljtbhlCountyCodedatamaps != null && ljtbhlCountyCodedatamaps.size() > 0) {
                            tbhlitemdata =
                                    ljtbhlCountyCodedatamaps.stream().collect(
                                            Collectors.groupingBy(item -> item.get("ItemCode").toString())
                                    );
                        }

                        String allhl = "0";
                        String allhk = "0";
                        String alltbhl = "0";
                        String alltbhk = "0";
                        //不累计月份的均值总值数据
                        List<String> allavghl = new ArrayList<>();
                        List<String> allavghk = new ArrayList<>();
                        List<String> allavgtbhl = new ArrayList<>();
                        List<String> allavgtbhk = new ArrayList<>();
                        for (Map<String, Object> Itemdata : ItemIsRiverEvalute) {
                            Object id = Itemdata.get("ID");//获取因子编码
                            Object CNName = Itemdata.get("CNName");//获取因子
                            //获取修约的标准值
                            String roundingOffstandardValue = "0";
                            if (hlroundingOffmaps != null && hlroundingOffmaps.size() > 0) {
                                for (Map<String, Object> data : hlroundingOffmaps) {
                                    Object standardValue = data.get("StandardValue");//标准值
                                    Object itemCodedata = data.get("ItemCode");//因子编码
                                    if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                        roundingOffstandardValue = String.valueOf(standardValue);
                                    }
                                }
                            }
                            //获取计算水质指数的标准值
                            String indexstandardValue = "0";
                            if (hlindexmaps != null && hlindexmaps.size() > 0) {
                                for (Map<String, Object> data : hlindexmaps) {
                                    Object standardValue = data.get("StandardValue");//标准值
                                    Object itemCodedata = data.get("ItemCode");//因子编码
                                    if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                        indexstandardValue = String.valueOf(standardValue);
                                    }
                                }
                            }
                            //获取修约的标准值
                            String hkroundingOffstandardValue = "0";
                            if (hkroundingOffmaps != null && hkroundingOffmaps.size() > 0) {
                                for (Map<String, Object> data : hkroundingOffmaps) {
                                    Object standardValue = data.get("StandardValue");//标准值
                                    Object itemCodedata = data.get("ItemCode");//因子编码
                                    if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                        hkroundingOffstandardValue = String.valueOf(standardValue);
                                    }
                                }
                            }
                            //获取计算水质指数的标准值
                            String hkindexstandardValue = "0";
                            if (hkindexmaps != null && hkindexmaps.size() > 0) {
                                for (Map<String, Object> data : hkindexmaps) {
                                    Object standardValue = data.get("StandardValue");//标准值
                                    Object itemCodedata = data.get("ItemCode");//因子编码
                                    if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                        hkindexstandardValue = String.valueOf(standardValue);
                                    }
                                }
                            }
                            List<Map<String, Object>> hkmaps = hkitemdata.get(id);
                            List<Map<String, Object>> hlmaps = hlitemdata.get(id);
                            List<Map<String, Object>> tbhkmaps = tbhkitemdata.get(id);
                            List<Map<String, Object>> tbhlmaps = tbhlitemdata.get(id);
                            List<String> avghl = new ArrayList<>();
                            List<String> avghk = new ArrayList<>();
                            List<String> avgtbhl = new ArrayList<>();
                            List<String> avgtbhk = new ArrayList<>();
                            if (hkmaps != null && hkmaps.size() > 0) {
                                for (Map<String, Object> hkmapsdata : hkmaps) {
                                    Object effectiveValue = hkmapsdata.get("EffectiveValue");
                                    Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                                    Object SampleDates = hkmapsdata.get("SampleDates");
                                    if (effectiveValue != null && !"".equals(effectiveValue)) {
                                        if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("2")) {
                                            avghk.add(String.valueOf(effectiveValue));
                                        }
                                    }
                                }
                            }
                            if (hlmaps != null && hlmaps.size() > 0) {
                                for (Map<String, Object> hkmapsdata : hlmaps) {
                                    Object effectiveValue = hkmapsdata.get("EffectiveValue");
                                    Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                                    Object SampleDates = hkmapsdata.get("SampleDates");
                                    if (effectiveValue != null && !"".equals(effectiveValue)) {
                                        if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("1")) {
                                            avghl.add(String.valueOf(effectiveValue));
                                        }
                                    }
                                }
                            }
                            if (tbhkmaps != null && tbhkmaps.size() > 0) {
                                for (Map<String, Object> hkmapsdata : tbhkmaps) {
                                    Object effectiveValue = hkmapsdata.get("EffectiveValue");
                                    Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                                    Object SampleDates = hkmapsdata.get("SampleDates");
                                    if (effectiveValue != null && !"".equals(effectiveValue)) {
                                        if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("2")) {
                                            avgtbhk.add(String.valueOf(effectiveValue));
                                        }
                                    }
                                }
                            }
                            if (tbhlmaps != null && tbhlmaps.size() > 0) {
                                for (Map<String, Object> hkmapsdata : tbhlmaps) {
                                    Object effectiveValue = hkmapsdata.get("EffectiveValue");
                                    Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                                    Object SampleDates = hkmapsdata.get("SampleDates");
                                    if (effectiveValue != null && !"".equals(effectiveValue)) {
                                        if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("1")) {
                                            avgtbhl.add(String.valueOf(effectiveValue));
                                        }
                                    }
                                }
                            }
                            //计算月份的水质指数
                            if (CNName != null && !"".equals(CNName)) {
                                if (avghl != null && avghl.size() > 0) {
                                    String dataValue = segmentFormula.avgdata(avghl);
                                    //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                                    Map maplistData = this.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(id), "", "1", "", "", String.valueOf(dataValue));
                                    if (maplistData != null && maplistData.size() > 0) {
                                        Object v = maplistData.get("_V"); //修约后的值
                                        Object in = maplistData.get("_IN");//单个因子的指数
                                        if (in != null && !"".equals(in)) {
                                            //数据计算总和得到河流/湖库/断面指数总和
                                            allavghl.add(String.valueOf(in));
                                        }
                                    }
                                }
                                if (avghk != null && avghk.size() > 0) {
                                    String dataValue = segmentFormula.avgdata(avghk);
                                    //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                                    Map maplistData = this.itemDataINV(hkindexstandardValue, hkroundingOffstandardValue, String.valueOf(id), "", "2", "", "", String.valueOf(dataValue));
                                    if (maplistData != null && maplistData.size() > 0) {
                                        Object v = maplistData.get("_V"); //修约后的值
                                        Object in = maplistData.get("_IN");//单个因子的指数
                                        if (in != null && !"".equals(in)) {
                                            //数据计算总和得到河流/湖库/断面指数总和
                                            allavghk.add(String.valueOf(in));
                                        }
                                    }
                                }
                                if (avgtbhl != null && avgtbhl.size() > 0) {
                                    String dataValue = segmentFormula.avgdata(avgtbhl);
                                    //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                                    Map maplistData = this.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(id), "", "1", "", "", String.valueOf(dataValue));
                                    if (maplistData != null && maplistData.size() > 0) {
                                        Object v = maplistData.get("_V"); //修约后的值
                                        Object in = maplistData.get("_IN");//单个因子的指数
                                        if (in != null && !"".equals(in)) {
                                            //数据计算总和得到河流/湖库/断面指数总和
                                            allavgtbhl.add(String.valueOf(in));
                                        }
                                    }
                                }
                                if (avgtbhk != null && avgtbhk.size() > 0) {
                                    String dataValue = segmentFormula.avgdata(avgtbhk);
                                    //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                                    Map maplistData = this.itemDataINV(hkindexstandardValue, hkroundingOffstandardValue, String.valueOf(id), "", "2", "", "", String.valueOf(dataValue));
                                    if (maplistData != null && maplistData.size() > 0) {
                                        Object v = maplistData.get("_V"); //修约后的值
                                        Object in = maplistData.get("_IN");//单个因子的指数
                                        if (in != null && !"".equals(in)) {
                                            //数据计算总和得到河流/湖库/断面指数总和
                                            allavgtbhk.add(String.valueOf(in));
                                        }
                                    }
                                }

                            }
                        }

                        //调用完工具类后所有水质指数进行相加总和数据
                        if (allavghl != null && allavghl.size() > 0) {
                            String dataValue = segmentFormula.noriverWaterQualityIndex(allavghl);
                            allhl = dataValue;
                        }
                        if (allavghk != null && allavghk.size() > 0) {
                            String dataValue = segmentFormula.noriverWaterQualityIndex(allavghk);
                            allhk = dataValue;
                        }

                        //hlIndex 河流水质指数, hlsize 河流数量, hkIndex 湖库水质指数, hksize 湖库数量
                        String index = segmentFormula.countyIndex(allhl, hlsize, allhk, hksize);
                        if (Double.valueOf(index) > 0) {
                            segmentdatamap.put("waterQualityIndex", Double.valueOf(index));
                        } else {
                            segmentdatamap.put("waterQualityIndex", null);
                        }

                        if (allavgtbhl != null && allavgtbhl.size() > 0) {
                            String dataValue = segmentFormula.noriverWaterQualityIndex(allavgtbhl);
                            alltbhl = dataValue;
                        }
                        if (allavgtbhk != null && allavgtbhk.size() > 0) {
                            String dataValue = segmentFormula.noriverWaterQualityIndex(allavgtbhk);
                            alltbhk = dataValue;
                        }
                        //hlIndex 河流水质指数, hlsize 河流数量, hkIndex 湖库水质指数, hksize 湖库数量
                        String tbindex = segmentFormula.countyIndex(alltbhl, tbhlsize, alltbhk, tbhksize);
                        if (Double.valueOf(tbindex) > 0) {
                            segmentdatamap.put("tbwaterQualityIndex", Double.valueOf(tbindex));
                        } else {
                            segmentdatamap.put("tbwaterQualityIndex", null);
                        }

                        //计算变换率 （年达标率-上年达标率）/上年达标率
                        if (index != null && tbindex != null && Double.valueOf(index) > 0 && Double.valueOf(tbindex) > 0 && !"0".equals(String.valueOf(index)) && !"0".equals(String.valueOf(tbindex))) {
                            Double v = Double.valueOf(index) - Double.valueOf(tbindex);
                            Double v1 = v / Double.valueOf(tbindex) * 100;
                            String format = format2.format(v1);
                            if (format.equals("∞")) {
                                segmentdatamap.put("change", null);
                            } else {
                                segmentdatamap.put("change", Double.valueOf(format));
                            }

                        } else {
                            segmentdatamap.put("change", null);
                        }
                    }
                }


                if (whetherYOY != null && whetherYOY.equals("1")) {
                    //判断时间为不为空
                    if (tbmonthall != null && tbmonthall.size() > 0) {
                        for (String mondata : tbmonthall) {
                            SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM");
                            Calendar tbcalendar = Calendar.getInstance();
                            try {
                                tbcalendar.setTime(dfs.parse(String.valueOf(mondata)));
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }
                            int tbmonth = tbcalendar.get(Calendar.MONTH);
                            int monthi = tbmonth + 1;
                            //存放计算好的湖库/河流水质指数
                            String hkdataall = "0";
                            String hldataall = "0";
                            //存放对应单因子的水质指数
                            List<String> hkdatastring = new ArrayList<>();
                            List<String> hldatastring = new ArrayList<>();
                            int tbhksizes = 0; //湖库断面id数量
                            int tbhlsizes = 0; //河流断面id数量
                            if (tbsegmentCountysl != null && tbsegmentCountysl.size() > 0) {
                                for (Map<String, Object> datasl : tbsegmentCountysl) {
                                    Object sl = datasl.get("sl");//数量
                                    Object countyCode = datasl.get("CountyCode");//区划编码
                                    Object segmentCategory = datasl.get("SegmentCategory");//断面类型 1是河流 2湖库
                                    Object county = datasl.get("County");//区划名称
                                    Object SampleDates = datasl.get("SampleDates");//监测时间
                                    if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                                        if (countyCode != null && countyCode.equals(codedata)) {
                                            if (SampleDates != null && SampleDates.equals(mondata)) {
                                                tbhlsizes = Integer.valueOf(String.valueOf(sl));
                                            }

                                        }
                                    }
                                    if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                                        if (countyCode != null && countyCode.equals(codedata)) {
                                            if (SampleDates != null && SampleDates.equals(mondata)) {
                                                tbhksizes = Integer.valueOf(String.valueOf(sl));
                                            }

                                        }
                                    }
                                }

                            }
                            if (tbhkCountyCodedatamaps != null && tbhkCountyCodedatamaps.size() > 0) {
                                for (Map<String, Object> hkdatas : tbhkCountyCodedatamaps) {
                                    Object countyCode = hkdatas.get("CountyCode");//区划编码
                                    Object county = hkdatas.get("County");//区划名称
                                    //segmentdatamap.put("county",county);
                                    Object assessTypeCode = hkdatas.get("AssessTypeCode");//断面类型编码
                                    Object assessType = hkdatas.get("AssessType");//断面类型
                                    Object sampleDate = hkdatas.get("SampleDate");//监测时间 月
                                    Object sampleDates = hkdatas.get("SampleDates");//监测时间 年月
                                    Object effectiveValue = hkdatas.get("EffectiveValue");//均值
                                    Object itemName = hkdatas.get("ItemName");//因子名称
                                    Object itemCode = hkdatas.get("ItemCode");//因子编码
                                    //判断因子和监测时间一样
                                    if (countyCode != null && countyCode.equals(codedata) && sampleDates != null && sampleDates.equals(mondata)) {
                                        //调用工具返回对应指数计算后的值 // _IN 指数 _V 均值
                                        if (itemName != null && !"".equals(itemName)) {
                                            //获取修约的标准值
                                            String roundingOffstandardValue = "0";
                                            if (hkroundingOffmaps != null && hkroundingOffmaps.size() > 0) {
                                                for (Map<String, Object> data : hkroundingOffmaps) {
                                                    Object standardValue = data.get("StandardValue");//标准值
                                                    Object itemCodedata = data.get("ItemCode");//因子编码
                                                    if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                        roundingOffstandardValue = String.valueOf(standardValue);
                                                    }
                                                }
                                            }
                                            //获取计算水质指数的标准值
                                            String indexstandardValue = "0";
                                            if (hkindexmaps != null && hkindexmaps.size() > 0) {
                                                for (Map<String, Object> data : hkindexmaps) {
                                                    Object standardValue = data.get("StandardValue");//标准值
                                                    Object itemCodedata = data.get("ItemCode");//因子编码
                                                    if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                        indexstandardValue = String.valueOf(standardValue);
                                                    }
                                                }
                                            }
                                            //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                                            Map maplistData = this.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(itemCode), "", "2", "", "", String.valueOf(effectiveValue));
                                            if (maplistData != null && maplistData.size() > 0) {
                                                Object v = maplistData.get("_V"); //修约后的值
                                                Object in = maplistData.get("_IN");//单个因子的指数
                                                if (in != null && !"".equals(in)) {
                                                    //数据计算总和得到河流/湖库/断面指数总和
                                                    hkdatastring.add(String.valueOf(in));
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            if (tbhlCountyCodedatamaps != null && tbhlCountyCodedatamaps.size() > 0) {
                                for (Map<String, Object> hldatas : tbhlCountyCodedatamaps) {
                                    Object countyCode = hldatas.get("CountyCode");//区划编码
                                    Object county = hldatas.get("County");//区划名称
                                    //  segmentdatamap.put("county",county);
                                    Object assessTypeCode = hldatas.get("AssessTypeCode");//断面类型编码
                                    Object assessType = hldatas.get("AssessType");//断面类型
                                    Object sampleDate = hldatas.get("SampleDate");//监测时间 月
                                    Object sampleDates = hldatas.get("SampleDates");//监测时间 年月
                                    Object effectiveValue = hldatas.get("EffectiveValue");//均值
                                    Object itemName = hldatas.get("ItemName");//因子名称
                                    Object itemCode = hldatas.get("ItemCode");//因子编码
                                    //判断因子和监测时间一样
                                    if (countyCode != null && countyCode.equals(codedata) && sampleDates != null && sampleDates.equals(mondata)) {
                                        //调用工具返回对应指数计算后的值 // _IN 指数 _V 均值
                                        if (itemName != null && !"".equals(itemName)) {
                                            //获取修约的标准值
                                            String roundingOffstandardValue = "0";
                                            if (hlroundingOffmaps != null && hlroundingOffmaps.size() > 0) {
                                                for (Map<String, Object> data : hlroundingOffmaps) {
                                                    Object standardValue = data.get("StandardValue");//标准值
                                                    Object itemCodedata = data.get("ItemCode");//因子编码
                                                    if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                        roundingOffstandardValue = String.valueOf(standardValue);
                                                    }
                                                }
                                            }
                                            //获取计算水质指数的标准值
                                            String indexstandardValue = "0";
                                            if (hlindexmaps != null && hlindexmaps.size() > 0) {
                                                for (Map<String, Object> data : hlindexmaps) {
                                                    Object standardValue = data.get("StandardValue");//标准值
                                                    Object itemCodedata = data.get("ItemCode");//因子编码
                                                    if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                        indexstandardValue = String.valueOf(standardValue);
                                                    }
                                                }
                                            }
                                            //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                                            Map maplistData = this.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(itemCode), "", "1", "", "", String.valueOf(effectiveValue));
                                            if (maplistData != null && maplistData.size() > 0) {
                                                Object v = maplistData.get("_V"); //修约后的值
                                                Object in = maplistData.get("_IN");//单个因子的指数
                                                if (in != null && !"".equals(in)) {
                                                    //数据计算总和得到河流/湖库/断面指数总和
                                                    hldatastring.add(String.valueOf(in));
                                                }
                                            }
                                        }
                                    }
                                }
                            }

                            //调用完工具类后所有水质指数进行相加总和数据
                            if (hkdatastring != null && hkdatastring.size() > 0) {
                                String dataValue = segmentFormula.noriverWaterQualityIndex(hkdatastring);
                                String effectiveValue = null;
                                //判断是否科学计算法，如果是就进行转换
                                boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(dataValue));
                                if (scientificNotation) {
                                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(dataValue));
                                    String effectiveValuesdatas = bigDecimal.toPlainString();
                                    effectiveValue = effectiveValuesdatas;
                                } else {
                                    effectiveValue = String.valueOf(dataValue);
                                }
                                hkdataall = effectiveValue;
                            }
                            if (hldatastring != null && hldatastring.size() > 0) {
                                String dataValue = segmentFormula.noriverWaterQualityIndex(hldatastring);
                                String effectiveValue = null;
                                //判断是否科学计算法，如果是就进行转换
                                boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(dataValue));
                                if (scientificNotation) {
                                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(dataValue));
                                    String effectiveValuesdatas = bigDecimal.toPlainString();
                                    effectiveValue = effectiveValuesdatas;
                                } else {
                                    effectiveValue = String.valueOf(dataValue);
                                }
                                hldataall = effectiveValue;
                            }
                            //hlIndex 河流水质指数, hlsize 河流数量, hkIndex 湖库水质指数, hksize 湖库数量
                            String index = segmentFormula.countyIndex(hldataall, tbhlsizes, hkdataall, tbhksizes);
                            if (Double.valueOf(index) > 0) {
                                segmentdatamap.put("tbwaterQualityIndex" + monthi, Double.valueOf(index));
                            } else {
                                segmentdatamap.put("tbwaterQualityIndex" + monthi, null);
                            }

                        }

                    }
                }
                //判断类型不能为空 如果为空就不去计算全部均值

                //判断时间为不为空
                if (monthall != null && monthall.size() > 0) {
                    for (String mondata : monthall) {
                        SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM");
                        Calendar tbcalendar = Calendar.getInstance();
                        try {
                            tbcalendar.setTime(dfs.parse(String.valueOf(mondata)));
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        int tbmonth = tbcalendar.get(Calendar.MONTH);
                        int monthi = tbmonth + 1;
                        //存放计算好的湖库/河流水质指数
                        String hkdataall = "0";
                        String hldataall = "0";
                        //存放对应单因子的水质指数
                        List<String> hkdatastring = new ArrayList<>();
                        List<String> hldatastring = new ArrayList<>();
                        int hksizes = 0; //湖库断面id数量
                        int hlsizes = 0; //河流断面id数量
                        if (segmentCountysl != null && segmentCountysl.size() > 0) {
                            for (Map<String, Object> datasl : segmentCountysl) {
                                Object sl = datasl.get("sl");//数量
                                Object countyCode = datasl.get("CountyCode");//区划编码
                                Object segmentCategory = datasl.get("SegmentCategory");//断面类型 1是河流 2湖库
                                Object county = datasl.get("County");//区划名称
                                Object SampleDates = datasl.get("SampleDates");//监测时间
                                if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                                    if (countyCode != null && countyCode.equals(codedata)) {
                                        if (SampleDates != null && SampleDates.equals(mondata)) {
                                            hlsizes = Integer.valueOf(String.valueOf(sl));
                                        }

                                    }
                                }
                                if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                                    if (countyCode != null && countyCode.equals(codedata)) {
                                        if (SampleDates != null && SampleDates.equals(mondata)) {
                                            hksizes = Integer.valueOf(String.valueOf(sl));
                                        }

                                    }
                                }
                            }

                        }
                        if (hkCountyCodedatamaps != null && hkCountyCodedatamaps.size() > 0) {
                            for (Map<String, Object> hkdatas : hkCountyCodedatamaps) {
                                Object countyCode = hkdatas.get("CountyCode");//区划编码
                                Object county = hkdatas.get("County");//区划名称
                                segmentdatamap.put("county", county);
                                Object assessTypeCode = hkdatas.get("AssessTypeCode");//断面类型编码
                                Object assessType = hkdatas.get("AssessType");//断面类型
                                Object sampleDate = hkdatas.get("SampleDate");//监测时间 月
                                Object sampleDates = hkdatas.get("SampleDates");//监测时间 年月
                                Object SegmentCategory = hkdatas.get("SegmentCategory");//监测时间 年月
                                Object effectiveValues = hkdatas.get("EffectiveValue");//均值
                                String effectiveValue = null;
                                //判断是否科学计算法，如果是就进行转换
                                boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                                if (scientificNotation) {
                                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                                    String effectiveValuesdatas = bigDecimal.toPlainString();
                                    effectiveValue = effectiveValuesdatas;
                                } else {
                                    effectiveValue = String.valueOf(effectiveValues);
                                }
                                Object itemName = hkdatas.get("ItemName");//因子名称
                                Object itemCode = hkdatas.get("ItemCode");//因子编码
                                //判断因子和监测时间一样
                                if (countyCode != null && countyCode.equals(codedata) && sampleDates != null && sampleDates.equals(mondata)) {
                                    //调用工具返回对应指数计算后的值 // _IN 指数 _V 均值
                                    if (itemName != null && !"".equals(itemName)) {
                                        //获取修约的标准值
                                        String roundingOffstandardValue = "0";
                                        if (hkroundingOffmaps != null && hkroundingOffmaps.size() > 0) {
                                            for (Map<String, Object> data : hkroundingOffmaps) {
                                                Object standardValue = data.get("StandardValue");//标准值
                                                Object itemCodedata = data.get("ItemCode");//因子编码
                                                if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                    roundingOffstandardValue = String.valueOf(standardValue);
                                                }
                                            }
                                        }
                                        //获取计算水质指数的标准值
                                        String indexstandardValue = "0";
                                        if (hkindexmaps != null && hkindexmaps.size() > 0) {
                                            for (Map<String, Object> data : hkindexmaps) {
                                                Object standardValue = data.get("StandardValue");//标准值
                                                Object itemCodedata = data.get("ItemCode");//因子编码
                                                if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                    indexstandardValue = String.valueOf(standardValue);
                                                }
                                            }
                                        }
                                        //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                                        Map maplistData = this.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(itemCode), "", "2", "", "", String.valueOf(effectiveValue));
                                        if (maplistData != null && maplistData.size() > 0) {
                                            Object v = maplistData.get("_V"); //修约后的值
                                            Object in = maplistData.get("_IN");//单个因子的指数
                                            if (in != null && !"".equals(in)) {
                                                //数据计算总和得到河流/湖库/断面指数总和
                                                hkdatastring.add(String.valueOf(in));
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        if (hlCountyCodedatamaps != null && hlCountyCodedatamaps.size() > 0) {
                            for (Map<String, Object> hldatas : hlCountyCodedatamaps) {
                                Object countyCode = hldatas.get("CountyCode");//区划编码
                                Object county = hldatas.get("County");//区划名称
                                segmentdatamap.put("county", county);
                                Object assessTypeCode = hldatas.get("AssessTypeCode");//断面类型编码
                                Object assessType = hldatas.get("AssessType");//断面类型
                                Object sampleDate = hldatas.get("SampleDate");//监测时间 月
                                Object sampleDates = hldatas.get("SampleDates");//监测时间 年月
                                Object effectiveValues = hldatas.get("EffectiveValue");//均值
                                String effectiveValue = null;
                                //判断是否科学计算法，如果是就进行转换
                                boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                                if (scientificNotation) {
                                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                                    String effectiveValuesdatas = bigDecimal.toPlainString();
                                    effectiveValue = effectiveValuesdatas;
                                } else {
                                    effectiveValue = String.valueOf(effectiveValues);
                                }
                                Object itemName = hldatas.get("ItemName");//因子名称
                                Object itemCode = hldatas.get("ItemCode");//因子编码
                                //判断因子和监测时间一样
                                if (countyCode != null && countyCode.equals(codedata) && sampleDates != null && sampleDates.equals(mondata)) {
                                    //调用工具返回对应指数计算后的值 // _IN 指数 _V 均值
                                    if (itemName != null && !"".equals(itemName)) {
                                        //获取修约的标准值
                                        String roundingOffstandardValue = "0";
                                        if (hlroundingOffmaps != null && hlroundingOffmaps.size() > 0) {
                                            for (Map<String, Object> data : hlroundingOffmaps) {
                                                Object standardValue = data.get("StandardValue");//标准值
                                                Object itemCodedata = data.get("ItemCode");//因子编码
                                                if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                    roundingOffstandardValue = String.valueOf(standardValue);
                                                }
                                            }
                                        }
                                        //获取计算水质指数的标准值
                                        String indexstandardValue = "0";
                                        if (hlindexmaps != null && hlindexmaps.size() > 0) {
                                            for (Map<String, Object> data : hlindexmaps) {
                                                Object standardValue = data.get("StandardValue");//标准值
                                                Object itemCodedata = data.get("ItemCode");//因子编码
                                                if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                    indexstandardValue = String.valueOf(standardValue);
                                                }
                                            }
                                        }
                                        //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                                        Map maplistData = this.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(itemCode), "", "1", "", "", String.valueOf(effectiveValue));
                                        if (maplistData != null && maplistData.size() > 0) {
                                            Object v = maplistData.get("_V"); //修约后的值
                                            Object in = maplistData.get("_IN");//单个因子的指数
                                            if (in != null && !"".equals(in)) {
                                                //数据计算总和得到河流/湖库/断面指数总和
                                                hldatastring.add(String.valueOf(in));
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        //调用完工具类后所有水质指数进行相加总和数据
                        if (hkdatastring != null && hkdatastring.size() > 0) {
                            String dataValue = segmentFormula.noriverWaterQualityIndex(hkdatastring);
                            String effectiveValue = null;
                            //判断是否科学计算法，如果是就进行转换
                            boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(dataValue));
                            if (scientificNotation) {
                                BigDecimal bigDecimal = new BigDecimal(String.valueOf(dataValue));
                                String effectiveValuesdatas = bigDecimal.toPlainString();
                                effectiveValue = effectiveValuesdatas;
                            } else {
                                effectiveValue = String.valueOf(dataValue);
                            }
                            hkdataall = effectiveValue;
                        }
                        if (hldatastring != null && hldatastring.size() > 0) {
                            String dataValue = segmentFormula.noriverWaterQualityIndex(hldatastring);
                            String effectiveValue = null;
                            //判断是否科学计算法，如果是就进行转换
                            boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(dataValue));
                            if (scientificNotation) {
                                BigDecimal bigDecimal = new BigDecimal(String.valueOf(dataValue));
                                String effectiveValuesdatas = bigDecimal.toPlainString();
                                effectiveValue = effectiveValuesdatas;
                            } else {
                                effectiveValue = String.valueOf(dataValue);
                            }
                            hldataall = effectiveValue;
                        }
                        //hlIndex 河流水质指数, hlsize 河流数量, hkIndex 湖库水质指数, hksize 湖库数量
                        String index = segmentFormula.countyIndex(hldataall, hlsizes, hkdataall, hksizes);
                        if (Double.valueOf(index) > 0) {
                            segmentdatamap.put("waterQualityIndex" + monthi, Double.valueOf(index));
                        } else {
                            segmentdatamap.put("waterQualityIndex" + monthi, null);
                        }
                    }

                }
                Object county = segmentdatamap.get("county");
                if (county != null && !"".equals(county)) {
                    maplist.add(segmentdatamap);
                }
                //maplist.add(segmentdatamap);

            }
        }
        //计算整体市级的
        //下面区县计算整体市级的已经抽取出去暂时先注释
        Map<String, Object> stringObjectMap = this.allcountySectionWaterQualityIndexses(map);
        mapdata.put("segmentdata", maplist);
        //市区的数据
        mapdata.put("allsegmentdata", stringObjectMap);


        return mapdata;
    }

    @Override
    public Map<String, Object> ljcountySectionWaterQualityIndex(Map<String, Object> map) {
        String maxSampleDate = busMonthlycumulativedataMapper.getbasicevaluatedatamaxSampleDate();
        Map<String, Object> mapdata = new HashMap<>();//返回值存放
        //修约位数
        DecimalFormat format2 = new DecimalFormat("#.00");
        SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM");
        //获取需要的数据
        //水质等级传一查询出修约需要的数据
        List<Map<String, Object>> hlroundingOffmaps = segmentFormula.wqBasStandardcategory("1", "1");
        //水质等级为三查询出水质指数计算的数据
        List<Map<String, Object>> hlindexmaps = segmentFormula.wqBasStandardcategory("1", "3");
        //水质等级传一查询出修约需要的数据
        List<Map<String, Object>> hkroundingOffmaps = segmentFormula.wqBasStandardcategory("2", "1");
        //水质等级为三查询出水质指数计算的数据
        List<Map<String, Object>> hkindexmaps = segmentFormula.wqBasStandardcategory("2", "3");
        List<String> cityCodes = (List<String>) map.get("CityCodes");//区划
        Object bussinessCategoryCode = map.get("bussinessCategoryCode");//数据类型
        List<String> monthall = (List<String>) map.get("monthall");//开始时间
        List<String> assessTypeCodes = (List<String>) map.get("assessTypeCodes");//考核
        List<String> hkSegmentIdsone = (List<String>) map.get("hkSegmentIdsone");//断面id
        List<String> hlSegmentIdsone = (List<String>) map.get("hlSegmentIdsone");//断面id
        //List<Map<String, Object>> ItemIsRiverEvalute = (List<Map<String, Object>>) map.get("ItemIsRiverEvalute");//参与计算因子
        Object whetherYOY = map.get("whetherYOY");//是否展示同比
        Object type = map.get("type");//不为空的话返回所有年份的总均值然后计算总体水质指数
        List<String> tbmonthall = (List<String>) map.get("tbmonthall");
        //获取断面id
        List<String> SegmentIds = (List<String>) map.get("SegmentIds");
        //获取月份条数
        int monthallsize = monthall.size();
        int tbmonthallsize = tbmonthall.size();
        //获取对应id的每个区划不通数据类型的数量
        List<Map<String, Object>> segmentCountysl = (List<Map<String, Object>>) map.get("segmentCountysl");
        List<Map<String, Object>> tbsegmentCountysl = (List<Map<String, Object>>) map.get("tbsegmentCountysl");

        //上面获取对应需要的参数
        List<Map<String, Object>> maplist = new ArrayList<>();
        //先判断传入的区划为空吗
        //需要调用sql语句进行查询均值然后计算数据
        //获取当前传入时间最大时间
        String nowDataTime = monthall.get(monthallsize - 1);
        if(nowDataTime!=null&&!"".equals(nowDataTime)){
            SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM");
            int i = maxSampleDate.compareTo(nowDataTime);
            System.out.println(i);
            if(i<0){
                nowDataTime=maxSampleDate;
            }

            //maxSampleDate
        }
        Integer year = DateUtils.getYear(nowDataTime, "yyyy-mm");
        //获取同比最大时间
        String tbDataTime = tbmonthall.get(tbmonthallsize - 1);
        Integer tbyear = DateUtils.getYear(tbDataTime, "yyyy-mm");
        List<Map<String, Object>> hkmanualIndexMonthlyDatalist = new ArrayList<>();
        if (hkSegmentIdsone != null && hkSegmentIdsone.size() > 0) {
            Map<String, Object> hkmanualIndexMonthlyDatamap = new HashMap<>();
            hkmanualIndexMonthlyDatamap.put("DataType", "5");
            hkmanualIndexMonthlyDatamap.put("beginTime", year + "-01");
            hkmanualIndexMonthlyDatamap.put("endTime", nowDataTime);
            hkmanualIndexMonthlyDatamap.put("AssessTownCode", cityCodes);
            hkmanualIndexMonthlyDatamap.put("SegmentIDs", hkSegmentIdsone);
            hkmanualIndexMonthlyDatamap.put("bussinessCategoryCode", bussinessCategoryCode);
            hkmanualIndexMonthlyDatamap.put("datatype", "CountyCode");//根据区划和因子分组查询
            hkmanualIndexMonthlyDatamap.put("datatypes", "CountyCode");//根据区划和因子分组查询
            //湖库均值数据
            hkmanualIndexMonthlyDatalist = busMonthlycumulativedataMapper.avgmanualIndexMonthlyData(hkmanualIndexMonthlyDatamap);

        }
        Map<String, Object> hlmanualIndexMonthlyDatamap = new HashMap<>();
        hlmanualIndexMonthlyDatamap.put("DataType", "5");
        hlmanualIndexMonthlyDatamap.put("beginTime", year + "-01");
        hlmanualIndexMonthlyDatamap.put("AssessTownCode", cityCodes);
        hlmanualIndexMonthlyDatamap.put("endTime", nowDataTime);
        hlmanualIndexMonthlyDatamap.put("SegmentIDs", hlSegmentIdsone);
        hlmanualIndexMonthlyDatamap.put("datatype", "CountyCode");//根据区划和因子分组查询
        hlmanualIndexMonthlyDatamap.put("datatypes", "CountyCode");//根据区划和因子分组查询
        //河流均值数据
        List<Map<String, Object>> hlmanualIndexMonthlyDatalist = busMonthlycumulativedataMapper.avgmanualIndexMonthlyData(hlmanualIndexMonthlyDatamap);

        //同比数据
        List<Map<String, Object>> tbhkmanualIndexMonthlyDatalist = new ArrayList<>();
        if (hkSegmentIdsone != null && hkSegmentIdsone.size() > 0) {
            Map<String, Object> tbhkmanualIndexMonthlyDatamap = new HashMap<>();
            tbhkmanualIndexMonthlyDatamap.put("DataType", "5");
            tbhkmanualIndexMonthlyDatamap.put("beginTime", tbyear + "-01");
            tbhkmanualIndexMonthlyDatamap.put("AssessTownCode", cityCodes);
            tbhkmanualIndexMonthlyDatamap.put("endTime", tbDataTime);
            tbhkmanualIndexMonthlyDatamap.put("SegmentIDs", hkSegmentIdsone);
            tbhkmanualIndexMonthlyDatamap.put("datatype", "CountyCode");//根据区划和因子分组查询
            tbhkmanualIndexMonthlyDatamap.put("datatypes", "CountyCode");//根据区划和因子分组查询
            //湖库均值数据
            tbhkmanualIndexMonthlyDatalist = busMonthlycumulativedataMapper.manualIndexMonthlyData(tbhkmanualIndexMonthlyDatamap);

        }
        Map<String, Object> tbhlmanualIndexMonthlyDatamap = new HashMap<>();
        tbhlmanualIndexMonthlyDatamap.put("DataType", "5");
        tbhlmanualIndexMonthlyDatamap.put("beginTime", tbyear + "-01");
        tbhlmanualIndexMonthlyDatamap.put("AssessTownCode", cityCodes);
        tbhlmanualIndexMonthlyDatamap.put("endTime", tbDataTime);
        tbhlmanualIndexMonthlyDatamap.put("SegmentIDs", hlSegmentIdsone);
        tbhlmanualIndexMonthlyDatamap.put("datatype", "CountyCode");//根据区划和因子分组查询
        tbhlmanualIndexMonthlyDatamap.put("datatypes", "CountyCode");//根据区划和因子分组查询
        //河流均值数据
        List<Map<String, Object>> tbhlmanualIndexMonthlyDatalist = busMonthlycumulativedataMapper.avgmanualIndexMonthlyData(tbhlmanualIndexMonthlyDatamap);
        List<Map<String, Object>> ljhkmanualIndexMonthlyDatalist = new ArrayList<>();
        if (hkSegmentIdsone != null && hkSegmentIdsone.size() > 0) {
            //下面查询区县整体均值不区分时间
            Map<String, Object> ljhkmanualIndexMonthlyDatamap = new HashMap<>();
            ljhkmanualIndexMonthlyDatamap.put("DataType", "5");
            ljhkmanualIndexMonthlyDatamap.put("beginTime", nowDataTime);
            ljhkmanualIndexMonthlyDatamap.put("AssessTownCode", cityCodes);
            ljhkmanualIndexMonthlyDatamap.put("endTime", nowDataTime);
            ljhkmanualIndexMonthlyDatamap.put("SegmentIDs", hkSegmentIdsone);
            ljhkmanualIndexMonthlyDatamap.put("datatype", "CountyCode");//根据区划和因子分组查询
            //湖库均值数据
            ljhkmanualIndexMonthlyDatalist = busMonthlycumulativedataMapper.avgmanualIndexMonthlyData(ljhkmanualIndexMonthlyDatamap);

        }
        Map<String, Object> ljhlmanualIndexMonthlyDatamap = new HashMap<>();
        ljhlmanualIndexMonthlyDatamap.put("DataType", "5");
        ljhlmanualIndexMonthlyDatamap.put("AssessTownCode", cityCodes);
        ljhlmanualIndexMonthlyDatamap.put("beginTime", nowDataTime);
        ljhlmanualIndexMonthlyDatamap.put("endTime", nowDataTime);
        ljhlmanualIndexMonthlyDatamap.put("SegmentIDs", hlSegmentIdsone);
        ljhlmanualIndexMonthlyDatamap.put("datatype", "CountyCode");//根据区划和因子分组查询
        //河流均值数据
        List<Map<String, Object>> ljhlmanualIndexMonthlyDatalist = busMonthlycumulativedataMapper.avgmanualIndexMonthlyData(ljhlmanualIndexMonthlyDatamap);

        //同比数据
        //湖库均值数据
        List<Map<String, Object>> ljtbhkmanualIndexMonthlyDatalist = new ArrayList<>();
        if (hkSegmentIdsone != null && hkSegmentIdsone.size() > 0) {
            Map<String, Object> ljtbhkmanualIndexMonthlyDatamap = new HashMap<>();
            ljtbhkmanualIndexMonthlyDatamap.put("DataType", "5");
            ljtbhkmanualIndexMonthlyDatamap.put("AssessTownCode", cityCodes);
            ljtbhkmanualIndexMonthlyDatamap.put("beginTime", tbDataTime);
            ljtbhkmanualIndexMonthlyDatamap.put("endTime", tbDataTime);
            ljtbhkmanualIndexMonthlyDatamap.put("SegmentIDs", hkSegmentIdsone);
            ljtbhkmanualIndexMonthlyDatamap.put("datatype", "CountyCode");//根据区划和因子分组查询
            ljtbhkmanualIndexMonthlyDatalist = busMonthlycumulativedataMapper.avgmanualIndexMonthlyData(ljtbhkmanualIndexMonthlyDatamap);

        }
        Map<String, Object> ljtbhlmanualIndexMonthlyDatamap = new HashMap<>();
        ljtbhlmanualIndexMonthlyDatamap.put("DataType", "5");
        ljtbhlmanualIndexMonthlyDatamap.put("AssessTownCode", cityCodes);
        ljtbhlmanualIndexMonthlyDatamap.put("beginTime", tbDataTime);
        ljtbhlmanualIndexMonthlyDatamap.put("endTime", tbDataTime);
        ljtbhlmanualIndexMonthlyDatamap.put("SegmentIDs", hlSegmentIdsone);
        ljtbhlmanualIndexMonthlyDatamap.put("datatype", "CountyCode");//根据区划和因子分组查询
        //河流均值数据
        List<Map<String, Object>> ljtbhlmanualIndexMonthlyDatalist = busMonthlycumulativedataMapper.avgmanualIndexMonthlyData(ljtbhlmanualIndexMonthlyDatamap);


        //先根据区划循环然后根据时间进行循环数据
        if (cityCodes != null && cityCodes.size() > 0) {
            for (String datacode : cityCodes) {
                //获取同比和当前的区划下的数量
                int hksize = 0;
                int hlsize = 0;
                int tbhksize = 0;
                int tbhlsize = 0;


                int hksizese = 0;
                int hlsizese = 0;
                int tbhksizese = 0;
                int tbhlsizese = 0;
                //累计的数据
                int ljhksize = 0;
                int ljhlsize = 0;
                int ljtbhksize = 0;
                int ljtbhlsize = 0;
                int segmentCountyslsize = 0;
                int tbsegmentCountyslsize = 0;
                if (segmentCountysl != null && segmentCountysl.size() > 0) {
                    for (Map<String, Object> datasl : segmentCountysl) {
                        Object sl = datasl.get("sl");//数量
                        Object countyCode = datasl.get("CountyCode");//区划编码
                        Object segmentCategory = datasl.get("SegmentCategory");//断面类型 1是河流 2湖库
                        Object county = datasl.get("County");//区划名称
                        Object SampleDates = datasl.get("SampleDates");//区划名称
                        if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                            if (countyCode != null && countyCode.equals(datacode)) {
                                if (hlsizese < Integer.valueOf(String.valueOf(sl))) {
                                    hlsizese = Integer.valueOf(String.valueOf(sl));
                                }
                            }
                        }
                        if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                            if (countyCode != null && countyCode.equals(datacode)) {
                                if (hksizese < Integer.valueOf(String.valueOf(sl))) {
                                    hksizese = Integer.valueOf(String.valueOf(sl));
                                }

                            }
                        }

                        if (SampleDates != null && !"".equals(SampleDates) && nowDataTime.equals(SampleDates)) {
                            //nowDataTime
                            if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                                if (countyCode != null && countyCode.equals(datacode)) {
                                    if (hlsize < Integer.valueOf(String.valueOf(sl))) {
                                        hlsize = Integer.valueOf(String.valueOf(sl));
                                    }
                                }
                            }
                            if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                                if (countyCode != null && countyCode.equals(datacode)) {
                                    if (hksize < Integer.valueOf(String.valueOf(sl))) {
                                        hksize = Integer.valueOf(String.valueOf(sl));
                                    }

                                }
                            }
                        }
                        segmentCountyslsize++;
                        int size = segmentCountysl.size();
                        if (segmentCountyslsize == size) {
                            if (hlsize <= 0) {
                                hlsize = hlsizese;
                            }
                            if (hksize <= 0) {
                                hksize = hksizese;
                            }
                        }

                    }

                }
                if (tbsegmentCountysl != null && tbsegmentCountysl.size() > 0) {
                    for (Map<String, Object> datasl : tbsegmentCountysl) {
                        Object sl = datasl.get("sl");//数量
                        Object countyCode = datasl.get("CountyCode");//区划编码
                        Object segmentCategory = datasl.get("SegmentCategory");//断面类型 1是河流 2湖库
                        Object county = datasl.get("County");//区划名称
                        //tbDataTime
                        Object SampleDates = datasl.get("SampleDates");//区划名称
                        if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                            if (countyCode != null && countyCode.equals(datacode)) {
                                if (tbhlsizese < Integer.valueOf(String.valueOf(sl))) {
                                    tbhlsizese = Integer.valueOf(String.valueOf(sl));
                                }

                            }
                        }
                        if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                            if (countyCode != null && countyCode.equals(datacode)) {
                                if (tbhksizese < Integer.valueOf(String.valueOf(sl))) {
                                    tbhksizese = Integer.valueOf(String.valueOf(sl));
                                }

                            }
                        }
                        if (SampleDates != null && !"".equals(SampleDates) && tbDataTime.equals(SampleDates)) {
                            //nowDataTime
                            if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                                if (countyCode != null && countyCode.equals(datacode)) {
                                    if (tbhlsize < Integer.valueOf(String.valueOf(sl))) {
                                        tbhlsize = Integer.valueOf(String.valueOf(sl));
                                    }

                                }
                            }
                            if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                                if (countyCode != null && countyCode.equals(datacode)) {
                                    if (tbhksize < Integer.valueOf(String.valueOf(sl))) {
                                        tbhksize = Integer.valueOf(String.valueOf(sl));
                                    }

                                }
                            }
                        }
                        tbsegmentCountyslsize++;
                        int size = tbsegmentCountysl.size();
                        if (tbsegmentCountyslsize == size) {
                            if (tbhlsize <= 0) {
                                tbhlsize = tbhlsizese;
                            }
                            if (tbhksize <= 0) {
                                tbhksize = tbhksizese;
                            }
                        }

                    }

                }
                //存放每个月的累计数据
                Map<String, Object> mapdatamoon = new HashMap<>();
                //得到数据进行分组查询
                List<Map<String, Object>> hklist = new ArrayList<>();
                List<Map<String, Object>> hllist = new ArrayList<>();
                if (hkmanualIndexMonthlyDatalist != null && hkmanualIndexMonthlyDatalist.size() > 0) {
                    //分组判断，stream流
                    Map<String, List<Map<String, Object>>> sunmapsSampleDate =
                            hkmanualIndexMonthlyDatalist.stream().collect(
                                    Collectors.groupingBy(item -> item.get("CountyCode").toString())
                            );
                    hklist = sunmapsSampleDate.get(String.valueOf(datacode));
                }
                if (hlmanualIndexMonthlyDatalist != null && hlmanualIndexMonthlyDatalist.size() > 0) {
                    //分组判断，stream流
                    Map<String, List<Map<String, Object>>> sunmapsSampleDate =
                            hlmanualIndexMonthlyDatalist.stream().collect(
                                    Collectors.groupingBy(item -> item.get("CountyCode").toString())
                            );
                    hllist = sunmapsSampleDate.get(String.valueOf(datacode));
                }
                //同比数据
                List<Map<String, Object>> tbhklist = new ArrayList<>();
                List<Map<String, Object>> tbhllist = new ArrayList<>();
                if (tbhkmanualIndexMonthlyDatalist != null && tbhkmanualIndexMonthlyDatalist.size() > 0) {
                    //分组判断，stream流
                    Map<String, List<Map<String, Object>>> sunmapsSampleDate =
                            tbhkmanualIndexMonthlyDatalist.stream().collect(
                                    Collectors.groupingBy(item -> item.get("CountyCode").toString())
                            );
                    tbhklist = sunmapsSampleDate.get(String.valueOf(datacode));
                }
                if (tbhlmanualIndexMonthlyDatalist != null && tbhlmanualIndexMonthlyDatalist.size() > 0) {
                    //分组判断，stream流
                    Map<String, List<Map<String, Object>>> sunmapsSampleDate =
                            tbhlmanualIndexMonthlyDatalist.stream().collect(
                                    Collectors.groupingBy(item -> item.get("CountyCode").toString())
                            );
                    tbhllist = sunmapsSampleDate.get(String.valueOf(datacode));
                }
                //累计数据
                //得到数据进行分组查询
                List<Map<String, Object>> ljhklist = new ArrayList<>();
                List<Map<String, Object>> ljhllist = new ArrayList<>();
                if (ljhkmanualIndexMonthlyDatalist != null && ljhkmanualIndexMonthlyDatalist.size() > 0) {
                    //分组判断，stream流
                    Map<String, List<Map<String, Object>>> sunmapsSampleDate =
                            ljhkmanualIndexMonthlyDatalist.stream().collect(
                                    Collectors.groupingBy(item -> item.get("CountyCode").toString())
                            );
                    ljhklist = sunmapsSampleDate.get(String.valueOf(datacode));
                }
                if (ljhlmanualIndexMonthlyDatalist != null && ljhlmanualIndexMonthlyDatalist.size() > 0) {
                    //分组判断，stream流
                    Map<String, List<Map<String, Object>>> sunmapsSampleDate =
                            ljhlmanualIndexMonthlyDatalist.stream().collect(
                                    Collectors.groupingBy(item -> item.get("CountyCode").toString())
                            );
                    ljhllist = sunmapsSampleDate.get(String.valueOf(datacode));
                }
                //同比数据
                List<Map<String, Object>> ljtbhklist = new ArrayList<>();
                List<Map<String, Object>> ljtbhllist = new ArrayList<>();
                if (ljtbhkmanualIndexMonthlyDatalist != null && ljtbhkmanualIndexMonthlyDatalist.size() > 0) {
                    //分组判断，stream流
                    Map<String, List<Map<String, Object>>> sunmapsSampleDate =
                            ljtbhkmanualIndexMonthlyDatalist.stream().collect(
                                    Collectors.groupingBy(item -> item.get("CountyCode").toString())
                            );
                    ljtbhklist = sunmapsSampleDate.get(String.valueOf(datacode));
                }
                if (ljtbhlmanualIndexMonthlyDatalist != null && ljtbhlmanualIndexMonthlyDatalist.size() > 0) {
                    //分组判断，stream流
                    Map<String, List<Map<String, Object>>> sunmapsSampleDate =
                            ljtbhlmanualIndexMonthlyDatalist.stream().collect(
                                    Collectors.groupingBy(item -> item.get("CountyCode").toString())
                            );
                    ljtbhllist = sunmapsSampleDate.get(String.valueOf(datacode));
                }
                //存放水质指数集合
                List<String> ljhkinter = new ArrayList<>();
                List<String> ljhlinter = new ArrayList<>();
                List<String> ljtbhkinter = new ArrayList<>();
                List<String> ljtbhlinter = new ArrayList<>();
                //根据上面分组数据得到当前区划当前时间的数据
                if (ljhklist != null && ljhklist.size() > 0) {
                    for (Map<String, Object> hkdata : ljhklist) {
                        Object countyCode = hkdata.get("CountyCode");//区划编码
                        Object county = hkdata.get("County");//区划名称
                        Object itemName = hkdata.get("ItemName");//因子名称
                        Object itemCode = hkdata.get("ItemCode");//因子id
                        Object segmentCategory = hkdata.get("SegmentCategory");//类型
                        Object effectiveValues = hkdata.get("EffectiveValue");//均值
                        String effectiveValue = null;
                        //判断是否科学计算法，如果是就进行转换
                        boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                        if (scientificNotation) {
                            BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                            String effectiveValuesdatas = bigDecimal.toPlainString();
                            effectiveValue = effectiveValuesdatas;
                        } else {
                            effectiveValue = String.valueOf(effectiveValues);
                        }
                        Object sampleDate = hkdata.get("SampleDate");//监测时间
                        Object yearData = hkdata.get("YearData");//年份
                        Object accumulatedMonths = hkdata.get("AccumulatedMonths");//累计月份
                        Object months = hkdata.get("Months");//月份
                        mapdatamoon.put("county", county);
                        mapdatamoon.put("countyCode", countyCode);
                        //调用工具返回对应指数计算后的值 // _IN 指数 _V 均值
                        if (itemName != null && !"".equals(itemName)) {
                            //获取修约的标准值
                            String roundingOffstandardValue = "0";
                            if (hkroundingOffmaps != null && hkroundingOffmaps.size() > 0) {
                                for (Map<String, Object> data : hkroundingOffmaps) {
                                    Object standardValue = data.get("StandardValue");//标准值
                                    Object itemCodedata = data.get("ItemCode");//因子编码
                                    if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                        roundingOffstandardValue = String.valueOf(standardValue);
                                    }
                                }
                            }
                            //获取计算水质指数的标准值
                            String indexstandardValue = "0";
                            if (hkindexmaps != null && hkindexmaps.size() > 0) {
                                for (Map<String, Object> data : hkindexmaps) {
                                    Object standardValue = data.get("StandardValue");//标准值
                                    Object itemCodedata = data.get("ItemCode");//因子编码
                                    if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                        indexstandardValue = String.valueOf(standardValue);
                                    }
                                }
                            }
                            String s = String.valueOf(itemName);
                            // indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值]
                            Map maplistData = segmentFormula.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(itemCode), String.valueOf(itemName), "2", "", "", String.valueOf(effectiveValue));
                            if (maplistData != null && maplistData.size() > 0) {
                                Object v = maplistData.get("_V"); //修约后的值
                                Object in = maplistData.get("_IN");//单个因子的指数
                                Object itemCodeData = maplistData.get("itemCode");//因子编码/id
                                maplistData.put(itemCode + "_IN", in);//水质指数
                                if (in != null && !"".equals(in)) {
                                    ljhkinter.add(String.valueOf(in));
                                }
                            }
                        }
                    }
                }
                if (ljhllist != null && ljhllist.size() > 0) {
                    for (Map<String, Object> hkdata : ljhllist) {
                        Object countyCode = hkdata.get("CountyCode");//区划编码
                        Object county = hkdata.get("County");//区划名称
                        Object itemName = hkdata.get("ItemName");//因子名称
                        Object itemCode = hkdata.get("ItemCode");//因子id
                        Object segmentCategory = hkdata.get("SegmentCategory");//类型
                        Object effectiveValues = hkdata.get("EffectiveValue");//均值
                        String effectiveValue = null;
                        //判断是否科学计算法，如果是就进行转换
                        boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                        if (scientificNotation) {
                            BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                            String effectiveValuesdatas = bigDecimal.toPlainString();
                            effectiveValue = effectiveValuesdatas;
                        } else {
                            effectiveValue = String.valueOf(effectiveValues);
                        }
                        Object sampleDate = hkdata.get("SampleDate");//监测时间
                        Object yearData = hkdata.get("YearData");//年份
                        Object accumulatedMonths = hkdata.get("AccumulatedMonths");//累计月份
                        Object months = hkdata.get("Months");//月份
                        mapdatamoon.put("county", county);
                        mapdatamoon.put("countyCode", countyCode);
                        //调用工具返回对应指数计算后的值 // _IN 指数 _V 均值
                        if (itemName != null && !"".equals(itemName)) {
                            //获取修约的标准值
                            String roundingOffstandardValue = "0";
                            if (hlroundingOffmaps != null && hlroundingOffmaps.size() > 0) {
                                for (Map<String, Object> data : hlroundingOffmaps) {
                                    Object standardValue = data.get("StandardValue");//标准值
                                    Object itemCodedata = data.get("ItemCode");//因子编码
                                    if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                        roundingOffstandardValue = String.valueOf(standardValue);
                                    }
                                }
                            }
                            //获取计算水质指数的标准值
                            String indexstandardValue = "0";
                            if (hlindexmaps != null && hlindexmaps.size() > 0) {
                                for (Map<String, Object> data : hlindexmaps) {
                                    Object standardValue = data.get("StandardValue");//标准值
                                    Object itemCodedata = data.get("ItemCode");//因子编码
                                    if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                        indexstandardValue = String.valueOf(standardValue);
                                    }
                                }
                            }
                            String s = String.valueOf(itemName);
                            // indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值]
                            Map maplistData = segmentFormula.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(itemCode), String.valueOf(itemName), "1", "", "", String.valueOf(effectiveValue));
                            if (maplistData != null && maplistData.size() > 0) {
                                Object v = maplistData.get("_V"); //修约后的值
                                Object in = maplistData.get("_IN");//单个因子的指数
                                Object itemCodeData = maplistData.get("itemCode");//因子编码/id
                                maplistData.put(itemCode + "_IN", in);//水质指数
                                if (in != null && !"".equals(in)) {
                                    ljhlinter.add(String.valueOf(in));
                                }
                            }
                        }
                    }
                }
                if (ljtbhklist != null && ljtbhklist.size() > 0) {
                    for (Map<String, Object> hkdata : ljtbhklist) {
                        Object countyCode = hkdata.get("CountyCode");//区划编码
                        Object county = hkdata.get("County");//区划名称
                        Object itemName = hkdata.get("ItemName");//因子名称
                        Object itemCode = hkdata.get("ItemCode");//因子id
                        Object segmentCategory = hkdata.get("SegmentCategory");//类型
                        Object effectiveValues = hkdata.get("EffectiveValue");//均值
                        String effectiveValue = null;
                        //判断是否科学计算法，如果是就进行转换
                        boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                        if (scientificNotation) {
                            BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                            String effectiveValuesdatas = bigDecimal.toPlainString();
                            effectiveValue = effectiveValuesdatas;
                        } else {
                            effectiveValue = String.valueOf(effectiveValues);
                        }
                        Object sampleDate = hkdata.get("SampleDate");//监测时间
                        Object yearData = hkdata.get("YearData");//年份
                        Object accumulatedMonths = hkdata.get("AccumulatedMonths");//累计月份
                        Object months = hkdata.get("Months");//月份
                        mapdatamoon.put("county", county);
                        mapdatamoon.put("countyCode", countyCode);
                        //调用工具返回对应指数计算后的值 // _IN 指数 _V 均值
                        if (itemName != null && !"".equals(itemName)) {
                            //获取修约的标准值
                            String roundingOffstandardValue = "0";
                            if (hkroundingOffmaps != null && hkroundingOffmaps.size() > 0) {
                                for (Map<String, Object> data : hkroundingOffmaps) {
                                    Object standardValue = data.get("StandardValue");//标准值
                                    Object itemCodedata = data.get("ItemCode");//因子编码
                                    if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                        roundingOffstandardValue = String.valueOf(standardValue);
                                    }
                                }
                            }
                            //获取计算水质指数的标准值
                            String indexstandardValue = "0";
                            if (hkindexmaps != null && hkindexmaps.size() > 0) {
                                for (Map<String, Object> data : hkindexmaps) {
                                    Object standardValue = data.get("StandardValue");//标准值
                                    Object itemCodedata = data.get("ItemCode");//因子编码
                                    if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                        indexstandardValue = String.valueOf(standardValue);
                                    }
                                }
                            }

                            // indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值]
                            Map maplistData = segmentFormula.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(itemCode), String.valueOf(itemName), "2", "", "", String.valueOf(effectiveValue));
                            if (maplistData != null && maplistData.size() > 0) {
                                Object v = maplistData.get("_V"); //修约后的值
                                Object in = maplistData.get("_IN");//单个因子的指数
                                Object itemCodeData = maplistData.get("itemCode");//因子编码/id
                                maplistData.put(itemCode + "_IN", in);//水质指数
                                if (in != null && !"".equals(in)) {
                                    ljtbhkinter.add(String.valueOf(in));
                                }
                            }
                        }
                    }
                }
                if (ljtbhllist != null && ljtbhllist.size() > 0) {
                    for (Map<String, Object> hkdata : ljtbhllist) {
                        Object countyCode = hkdata.get("CountyCode");//区划编码
                        Object county = hkdata.get("County");//区划名称
                        Object itemName = hkdata.get("ItemName");//因子名称
                        Object itemCode = hkdata.get("ItemCode");//因子id
                        Object segmentCategory = hkdata.get("SegmentCategory");//类型
                        Object effectiveValues = hkdata.get("EffectiveValue");//均值
                        String effectiveValue = null;
                        //判断是否科学计算法，如果是就进行转换
                        boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                        if (scientificNotation) {
                            BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                            String effectiveValuesdatas = bigDecimal.toPlainString();
                            effectiveValue = effectiveValuesdatas;
                        } else {
                            effectiveValue = String.valueOf(effectiveValues);
                        }
                        Object sampleDate = hkdata.get("SampleDate");//监测时间
                        Object yearData = hkdata.get("YearData");//年份
                        Object accumulatedMonths = hkdata.get("AccumulatedMonths");//累计月份
                        Object months = hkdata.get("Months");//月份
                        mapdatamoon.put("county", county);
                        mapdatamoon.put("countyCode", countyCode);
                        //调用工具返回对应指数计算后的值 // _IN 指数 _V 均值
                        if (itemName != null && !"".equals(itemName)) {
                            //获取修约的标准值
                            String roundingOffstandardValue = "0";
                            if (hlroundingOffmaps != null && hlroundingOffmaps.size() > 0) {
                                for (Map<String, Object> data : hlroundingOffmaps) {
                                    Object standardValue = data.get("StandardValue");//标准值
                                    Object itemCodedata = data.get("ItemCode");//因子编码
                                    if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                        roundingOffstandardValue = String.valueOf(standardValue);
                                    }
                                }
                            }
                            //获取计算水质指数的标准值
                            String indexstandardValue = "0";
                            if (hlindexmaps != null && hlindexmaps.size() > 0) {
                                for (Map<String, Object> data : hlindexmaps) {
                                    Object standardValue = data.get("StandardValue");//标准值
                                    Object itemCodedata = data.get("ItemCode");//因子编码
                                    if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                        indexstandardValue = String.valueOf(standardValue);
                                    }
                                }
                            }

                            // indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值]
                            Map maplistData = segmentFormula.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(itemCode), String.valueOf(itemName), "1", "", "", String.valueOf(effectiveValue));
                            if (maplistData != null && maplistData.size() > 0) {
                                Object v = maplistData.get("_V"); //修约后的值
                                Object in = maplistData.get("_IN");//单个因子的指数
                                Object itemCodeData = maplistData.get("itemCode");//因子编码/id
                                maplistData.put(itemCode + "_IN", in);//水质指数
                                if (in != null && !"".equals(in)) {
                                    ljtbhlinter.add(String.valueOf(in));
                                }
                            }
                        }
                    }
                }
                //根据累计分组数据进行计算水质指数
                //调用完工具类后所有水质指数进行相加总和数据
                String ljhkIndex = "0";
                String ljhlIndex = "0";
                String ljtbhkIndex = "0";
                String ljtbhlIndex = "0";
                if (ljhkinter != null && ljhkinter.size() > 0) {
                    String dataValue = segmentFormula.noriverWaterQualityIndex(ljhkinter);
                    ljhkIndex = dataValue;
                }
                if (ljhlinter != null && ljhlinter.size() > 0) {
                    String dataValue = segmentFormula.noriverWaterQualityIndex(ljhlinter);
                    ljhlIndex = dataValue;
                }
                //[hlIndex 河流水质指数, hlsize 河流数量, hkIndex 湖库水质指数, hksize 湖库数量]
                String ljnowindex = segmentFormula.countyIndex(ljhlIndex, hlsize, ljhkIndex, hksize);
                if (Double.valueOf(ljnowindex) > 0) {
                    mapdatamoon.put("waterQualityIndex", Double.valueOf(ljnowindex));
                } else {
                    mapdatamoon.put("waterQualityIndex", null);
                }

                if (ljtbhkinter != null && ljtbhkinter.size() > 0) {
                    String dataValue = segmentFormula.noriverWaterQualityIndex(ljtbhkinter);
                    ljtbhkIndex = dataValue;
                }
                if (ljtbhlinter != null && ljtbhlinter.size() > 0) {
                    String dataValue = segmentFormula.noriverWaterQualityIndex(ljtbhlinter);
                    ljtbhlIndex = dataValue;
                }
                //[hlIndex 河流水质指数, hlsize 河流数量, hkIndex 湖库水质指数, hksize 湖库数量]
                String ljtbindex = segmentFormula.countyIndex(ljtbhlIndex, tbhlsize, ljtbhkIndex, tbhksize);
                if (Double.valueOf(ljtbindex) > 0) {
                    mapdatamoon.put("tbwaterQualityIndex", Double.valueOf(ljtbindex));
                } else {
                    mapdatamoon.put("tbwaterQualityIndex", null);
                }

                //计算变换率 （年达标率-上年达标率）/上年达标率
                if (ljnowindex != null && ljtbindex != null && Double.valueOf(ljnowindex) > 0 && Double.valueOf(ljtbindex) > 0 && !"0".equals(String.valueOf(ljnowindex)) && !"0".equals(String.valueOf(ljtbindex))) {
                    Double v = Double.valueOf(ljnowindex) - Double.valueOf(ljtbindex);
                    Double v1 = v / Double.valueOf(ljtbindex) * 100;
                    String format = format2.format(v1);
                    if (format.equals("∞")) {
                        mapdatamoon.put("change", null);
                    } else {
                        mapdatamoon.put("change", Double.valueOf(format));
                    }

                } else {
                    mapdatamoon.put("change", null);
                }


                if (monthall != null && monthall.size() > 0) {
                    //循环时间进行累计
                    for (String datamoon : monthall) {
                        //获取月份
                        // SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM");
                        Calendar tbcalendar = Calendar.getInstance();
                        try {
                            tbcalendar.setTime(dfs.parse(String.valueOf(datamoon)));
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        int tbmonth = tbcalendar.get(Calendar.MONTH);
                        int monthi = tbmonth + 1;
                        String monthis;
                        if (tbmonth < 9) {
                            monthis = "0" + (tbmonth + 1);

                        } else {
                            monthis = String.valueOf((tbmonth + 1));

                        }
                        int monhksize = 0;
                        int monhlsize = 0;
                        int montbhksize = 0;
                        int montbhlsize = 0;

                        int monhksizese = 0;
                        int monhlsizese = 0;
                        int tbmonhksizese = 0;
                        int tbmonhlsizese = 0;
                        int monsegmentCountyslsize = 0;
                        int montbsegmentCountyslsize = 0;
                        if (segmentCountysl != null && segmentCountysl.size() > 0) {
                            for (Map<String, Object> datasl : segmentCountysl) {
                                Object sl = datasl.get("sl");//数量
                                Object countyCode = datasl.get("CountyCode");//区划编码
                                Object segmentCategory = datasl.get("SegmentCategory");//断面类型 1是河流 2湖库
                                Object county = datasl.get("County");//区划名称
                                Object SampleDates = datasl.get("SampleDates");//区划名称
                                if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                                    if (countyCode != null && countyCode.equals(datacode)) {
                                        if (monhlsizese < Integer.valueOf(String.valueOf(sl))) {
                                            monhlsizese = Integer.valueOf(String.valueOf(sl));
                                        }
                                    }
                                }
                                if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                                    if (countyCode != null && countyCode.equals(datacode)) {
                                        if (monhksizese < Integer.valueOf(String.valueOf(sl))) {
                                            monhksizese = Integer.valueOf(String.valueOf(sl));
                                        }

                                    }
                                }
                                if (SampleDates != null && datamoon.equals(SampleDates)) {
                                    if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                                        if (countyCode != null && countyCode.equals(datacode)) {
                                            if (monhlsize < Integer.valueOf(String.valueOf(sl))) {
                                                monhlsize = Integer.valueOf(String.valueOf(sl));
                                            }
                                        }
                                    }
                                    if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                                        if (countyCode != null && countyCode.equals(datacode)) {
                                            if (monhksize < Integer.valueOf(String.valueOf(sl))) {
                                                monhksize = Integer.valueOf(String.valueOf(sl));
                                            }

                                        }
                                    }
                                }
                                monsegmentCountyslsize++;
                                int size = segmentCountysl.size();
                                if (monsegmentCountyslsize == size) {
                                    if (monhlsize <= 0) {
                                        monhlsize = monhlsizese;
                                    }
                                    if (monhksize <= 0) {
                                        monhksize = monhksizese;
                                    }
                                }
                            }
                        }
                        if (tbsegmentCountysl != null && tbsegmentCountysl.size() > 0) {
                            for (Map<String, Object> datasl : tbsegmentCountysl) {
                                Object sl = datasl.get("sl");//数量
                                Object countyCode = datasl.get("CountyCode");//区划编码
                                Object segmentCategory = datasl.get("SegmentCategory");//断面类型 1是河流 2湖库
                                Object county = datasl.get("County");//区划名称
                                Object SampleDates = datasl.get("SampleDates");//区划名称
                                if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                                    if (countyCode != null && countyCode.equals(datacode)) {
                                        if (tbmonhlsizese < Integer.valueOf(String.valueOf(sl))) {
                                            tbmonhlsizese = Integer.valueOf(String.valueOf(sl));
                                        }

                                    }
                                }
                                if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                                    if (countyCode != null && countyCode.equals(datacode)) {
                                        if (tbmonhksizese < Integer.valueOf(String.valueOf(sl))) {
                                            tbmonhksizese = Integer.valueOf(String.valueOf(sl));
                                        }

                                    }
                                }

                                if (SampleDates != null && !"".equals(SampleDates)) {
                                    String month = DateUtils.MONTH(String.valueOf(SampleDates), "yyyy-MM");
                                    if (month != null && monthis.equals(month)) {
                                        if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                                            if (countyCode != null && countyCode.equals(datacode)) {
                                                if (montbhlsize < Integer.valueOf(String.valueOf(sl))) {
                                                    montbhlsize = Integer.valueOf(String.valueOf(sl));
                                                }

                                            }
                                        }
                                        if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                                            if (countyCode != null && countyCode.equals(datacode)) {
                                                if (montbhksize < Integer.valueOf(String.valueOf(sl))) {
                                                    montbhksize = Integer.valueOf(String.valueOf(sl));
                                                }

                                            }
                                        }
                                    }
                                }
                                montbsegmentCountyslsize++;
                                int size = tbsegmentCountysl.size();
                                if (montbsegmentCountyslsize == size) {
                                    if (montbhlsize <= 0) {
                                        montbhlsize = tbmonhlsizese;
                                    }
                                    if (montbhksize <= 0) {
                                        montbhksize = tbmonhksizese;
                                    }
                                }

                            }

                        }
                        //存放水质指数集合
                        List<String> hkinter = new ArrayList<>();
                        List<String> hlinter = new ArrayList<>();
                        List<String> tbhkinter = new ArrayList<>();
                        List<String> tbhlinter = new ArrayList<>();
                        List<Map<String, Object>> hkcodelist = new ArrayList<>();
                        List<Map<String, Object>> hlcodelist = new ArrayList<>();
                        if (hklist != null && hklist.size() > 0) {
                            //分组判断，stream流
                            Map<String, List<Map<String, Object>>> sunmapsSampleDate =
                                    hklist.stream().collect(
                                            Collectors.groupingBy(item -> item.get("SampleDate").toString())
                                    );
                            hkcodelist = sunmapsSampleDate.get(String.valueOf(datamoon));
                        }
                        if (hllist != null && hllist.size() > 0) {
                            //分组判断，stream流
                            Map<String, List<Map<String, Object>>> sunmapsSampleDate =
                                    hllist.stream().collect(
                                            Collectors.groupingBy(item -> item.get("SampleDate").toString())
                                    );
                            hlcodelist = sunmapsSampleDate.get(String.valueOf(datamoon));
                        }
                        //根据上面两次分组数据得到当前区划当前时间的数据
                        if (hkcodelist != null && hkcodelist.size() > 0) {
                            for (Map<String, Object> hkdata : hkcodelist) {
                                Object countyCode = hkdata.get("CountyCode");//区划编码
                                Object county = hkdata.get("County");//区划名称
                                Object itemName = hkdata.get("ItemName");//因子名称
                                Object itemCode = hkdata.get("ItemCode");//因子id
                                Object segmentCategory = hkdata.get("SegmentCategory");//类型
                                Object effectiveValues = hkdata.get("EffectiveValue");//均值
                                String effectiveValue = null;
                                //判断是否科学计算法，如果是就进行转换
                                boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                                if (scientificNotation) {
                                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                                    String effectiveValuesdatas = bigDecimal.toPlainString();
                                    effectiveValue = effectiveValuesdatas;
                                } else {
                                    effectiveValue = String.valueOf(effectiveValues);
                                }
                                Object sampleDate = hkdata.get("SampleDate");//监测时间
                                Object yearData = hkdata.get("YearData");//年份
                                Object accumulatedMonths = hkdata.get("AccumulatedMonths");//累计月份
                                Object months = hkdata.get("Months");//月份
                                mapdatamoon.put("county", county);
                                mapdatamoon.put("countyCode", countyCode);
                                //调用工具返回对应指数计算后的值 // _IN 指数 _V 均值
                                if (itemName != null && !"".equals(itemName)) {
                                    //获取修约的标准值
                                    String roundingOffstandardValue = "0";
                                    if (hkroundingOffmaps != null && hkroundingOffmaps.size() > 0) {
                                        for (Map<String, Object> data : hkroundingOffmaps) {
                                            Object standardValue = data.get("StandardValue");//标准值
                                            Object itemCodedata = data.get("ItemCode");//因子编码
                                            if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                roundingOffstandardValue = String.valueOf(standardValue);
                                            }
                                        }
                                    }
                                    //获取计算水质指数的标准值
                                    String indexstandardValue = "0";
                                    if (hkindexmaps != null && hkindexmaps.size() > 0) {
                                        for (Map<String, Object> data : hkindexmaps) {
                                            Object standardValue = data.get("StandardValue");//标准值
                                            Object itemCodedata = data.get("ItemCode");//因子编码
                                            if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                indexstandardValue = String.valueOf(standardValue);
                                            }
                                        }
                                    }
                                    String s = String.valueOf(itemName);
                                    // indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值]
                                    Map maplistData = segmentFormula.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(itemCode), String.valueOf(itemName), "2", "", "", String.valueOf(effectiveValue));
                                    if (maplistData != null && maplistData.size() > 0) {
                                        Object v = maplistData.get("_V"); //修约后的值
                                        Object in = maplistData.get("_IN");//单个因子的指数
                                        Object itemCodeData = maplistData.get("itemCode");//因子编码/id
                                        maplistData.put(itemCode + "_IN", in);//水质指数
                                        if (in != null && !"".equals(in)) {
                                            hkinter.add(String.valueOf(in));
                                        }
                                    }
                                }
                            }
                        }
                        if (hlcodelist != null && hlcodelist.size() > 0) {
                            for (Map<String, Object> hkdata : hlcodelist) {
                                Object countyCode = hkdata.get("CountyCode");//区划编码
                                Object county = hkdata.get("County");//区划名称
                                Object itemName = hkdata.get("ItemName");//因子名称
                                Object itemCode = hkdata.get("ItemCode");//因子id
                                Object segmentCategory = hkdata.get("SegmentCategory");//类型
                                Object effectiveValues = hkdata.get("EffectiveValue");//均值
                                String effectiveValue = null;
                                //判断是否科学计算法，如果是就进行转换
                                boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                                if (scientificNotation) {
                                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                                    String effectiveValuesdatas = bigDecimal.toPlainString();
                                    effectiveValue = effectiveValuesdatas;
                                } else {
                                    effectiveValue = String.valueOf(effectiveValues);
                                }
                                Object sampleDate = hkdata.get("SampleDate");//监测时间
                                Object yearData = hkdata.get("YearData");//年份
                                Object accumulatedMonths = hkdata.get("AccumulatedMonths");//累计月份
                                Object months = hkdata.get("Months");//月份
                                mapdatamoon.put("county", county);
                                mapdatamoon.put("countyCode", countyCode);
                                //调用工具返回对应指数计算后的值 // _IN 指数 _V 均值
                                if (itemName != null && !"".equals(itemName)) {
                                    //获取修约的标准值
                                    String roundingOffstandardValue = "0";
                                    if (hlroundingOffmaps != null && hlroundingOffmaps.size() > 0) {
                                        for (Map<String, Object> data : hlroundingOffmaps) {
                                            Object standardValue = data.get("StandardValue");//标准值
                                            Object itemCodedata = data.get("ItemCode");//因子编码
                                            if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                roundingOffstandardValue = String.valueOf(standardValue);
                                            }
                                        }
                                    }
                                    //获取计算水质指数的标准值
                                    String indexstandardValue = "0";
                                    if (hlindexmaps != null && hlindexmaps.size() > 0) {
                                        for (Map<String, Object> data : hlindexmaps) {
                                            Object standardValue = data.get("StandardValue");//标准值
                                            Object itemCodedata = data.get("ItemCode");//因子编码
                                            if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                indexstandardValue = String.valueOf(standardValue);
                                            }
                                        }
                                    }
                                    String s = String.valueOf(itemName);
                                    // indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值]
                                    Map maplistData = segmentFormula.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(itemCode), String.valueOf(itemName), "1", "", "", String.valueOf(effectiveValue));
                                    if (maplistData != null && maplistData.size() > 0) {
                                        Object v = maplistData.get("_V"); //修约后的值
                                        Object in = maplistData.get("_IN");//单个因子的指数
                                        Object itemCodeData = maplistData.get("itemCode");//因子编码/id
                                        maplistData.put(itemCode + "_IN", in);//水质指数
                                        if (in != null && !"".equals(in)) {
                                            hlinter.add(String.valueOf(in));
                                        }
                                    }
                                }
                            }
                        }
                        if (whetherYOY != null && whetherYOY.equals("1")) {
                            List<Map<String, Object>> tbhkcodelist = new ArrayList<>();
                            List<Map<String, Object>> tbhlcodelist = new ArrayList<>();
                            if (tbhklist != null && tbhklist.size() > 0) {
                                //分组判断，stream流
                                Map<String, List<Map<String, Object>>> sunmapsSampleDate =
                                        tbhklist.stream().collect(
                                                Collectors.groupingBy(item -> item.get("SampleDate").toString())
                                        );
                                tbhkcodelist = sunmapsSampleDate.get(String.valueOf(tbyear + "-" + monthis));
                            }
                            if (tbhllist != null && tbhllist.size() > 0) {
                                //分组判断，stream流
                                Map<String, List<Map<String, Object>>> sunmapsSampleDate =
                                        tbhllist.stream().collect(
                                                Collectors.groupingBy(item -> item.get("SampleDate").toString())
                                        );
                                tbhlcodelist = sunmapsSampleDate.get(String.valueOf(tbyear + "-" + monthis));
                            }
                            //根据上面两次分组数据得到当前区划当前时间的数据
                            if (tbhkcodelist != null && tbhkcodelist.size() > 0) {
                                for (Map<String, Object> hkdata : tbhkcodelist) {
                                    Object countyCode = hkdata.get("CountyCode");//区划编码
                                    Object county = hkdata.get("County");//区划名称
                                    Object itemName = hkdata.get("ItemName");//因子名称
                                    Object itemCode = hkdata.get("ItemCode");//因子id
                                    Object segmentCategory = hkdata.get("SegmentCategory");//类型
                                    Object effectiveValues = hkdata.get("EffectiveValue");//均值
                                    String effectiveValue = null;
                                    //判断是否科学计算法，如果是就进行转换
                                    boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                                    if (scientificNotation) {
                                        BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                                        String effectiveValuesdatas = bigDecimal.toPlainString();
                                        effectiveValue = effectiveValuesdatas;
                                    } else {
                                        effectiveValue = String.valueOf(effectiveValues);
                                    }
                                    Object sampleDate = hkdata.get("SampleDate");//监测时间
                                    Object yearData = hkdata.get("YearData");//年份
                                    Object accumulatedMonths = hkdata.get("AccumulatedMonths");//累计月份
                                    Object months = hkdata.get("Months");//月份
                                    mapdatamoon.put("county", county);
                                    mapdatamoon.put("countyCode", countyCode);
                                    //调用工具返回对应指数计算后的值 // _IN 指数 _V 均值
                                    if (itemName != null && !"".equals(itemName)) {
                                        //获取修约的标准值
                                        String roundingOffstandardValue = "0";
                                        if (hkroundingOffmaps != null && hkroundingOffmaps.size() > 0) {
                                            for (Map<String, Object> data : hkroundingOffmaps) {
                                                Object standardValue = data.get("StandardValue");//标准值
                                                Object itemCodedata = data.get("ItemCode");//因子编码
                                                if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                    roundingOffstandardValue = String.valueOf(standardValue);
                                                }
                                            }
                                        }
                                        //获取计算水质指数的标准值
                                        String indexstandardValue = "0";
                                        if (hkindexmaps != null && hkindexmaps.size() > 0) {
                                            for (Map<String, Object> data : hkindexmaps) {
                                                Object standardValue = data.get("StandardValue");//标准值
                                                Object itemCodedata = data.get("ItemCode");//因子编码
                                                if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                    indexstandardValue = String.valueOf(standardValue);
                                                }
                                            }
                                        }
                                        String s = String.valueOf(itemName);
                                        // indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值]
                                        Map maplistData = segmentFormula.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(itemCode), String.valueOf(itemName), "2", "", "", String.valueOf(effectiveValue));
                                        if (maplistData != null && maplistData.size() > 0) {
                                            Object v = maplistData.get("_V"); //修约后的值
                                            Object in = maplistData.get("_IN");//单个因子的指数
                                            Object itemCodeData = maplistData.get("itemCode");//因子编码/id
                                            maplistData.put(itemCode + "_IN", in);//水质指数
                                            if (in != null && !"".equals(in)) {
                                                tbhkinter.add(String.valueOf(in));
                                            }
                                        }
                                    }
                                }
                            }
                            if (tbhlcodelist != null && tbhlcodelist.size() > 0) {
                                for (Map<String, Object> hkdata : tbhlcodelist) {
                                    Object countyCode = hkdata.get("CountyCode");//区划编码
                                    Object county = hkdata.get("County");//区划名称
                                    Object itemName = hkdata.get("ItemName");//因子名称
                                    Object itemCode = hkdata.get("ItemCode");//因子id
                                    Object segmentCategory = hkdata.get("SegmentCategory");//类型
                                    Object effectiveValues = hkdata.get("EffectiveValue");//均值
                                    String effectiveValue = null;
                                    //判断是否科学计算法，如果是就进行转换
                                    boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                                    if (scientificNotation) {
                                        BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                                        String effectiveValuesdatas = bigDecimal.toPlainString();
                                        effectiveValue = effectiveValuesdatas;
                                    } else {
                                        effectiveValue = String.valueOf(effectiveValues);
                                    }
                                    Object sampleDate = hkdata.get("SampleDate");//监测时间
                                    Object yearData = hkdata.get("YearData");//年份
                                    Object accumulatedMonths = hkdata.get("AccumulatedMonths");//累计月份
                                    Object months = hkdata.get("Months");//月份
                                    mapdatamoon.put("county", county);
                                    mapdatamoon.put("countyCode", countyCode);
                                    //调用工具返回对应指数计算后的值 // _IN 指数 _V 均值
                                    if (itemName != null && !"".equals(itemName)) {
                                        //获取修约的标准值
                                        String roundingOffstandardValue = "0";
                                        if (hlroundingOffmaps != null && hlroundingOffmaps.size() > 0) {
                                            for (Map<String, Object> data : hlroundingOffmaps) {
                                                Object standardValue = data.get("StandardValue");//标准值
                                                Object itemCodedata = data.get("ItemCode");//因子编码
                                                if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                    roundingOffstandardValue = String.valueOf(standardValue);
                                                }
                                            }
                                        }
                                        //获取计算水质指数的标准值
                                        String indexstandardValue = "0";
                                        if (hlindexmaps != null && hlindexmaps.size() > 0) {
                                            for (Map<String, Object> data : hlindexmaps) {
                                                Object standardValue = data.get("StandardValue");//标准值
                                                Object itemCodedata = data.get("ItemCode");//因子编码
                                                if (itemCode != null && !"".equals(itemCode) && itemCodedata.equals(itemCode)) {
                                                    indexstandardValue = String.valueOf(standardValue);
                                                }
                                            }
                                        }
                                        String s = String.valueOf(itemName);
                                        // indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值]
                                        Map maplistData = segmentFormula.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(itemCode), String.valueOf(itemName), "1", "", "", String.valueOf(effectiveValue));
                                        if (maplistData != null && maplistData.size() > 0) {
                                            Object v = maplistData.get("_V"); //修约后的值
                                            Object in = maplistData.get("_IN");//单个因子的指数
                                            Object itemCodeData = maplistData.get("itemCode");//因子编码/id
                                            maplistData.put(itemCode + "_IN", in);//水质指数
                                            if (in != null && !"".equals(in)) {
                                                tbhlinter.add(String.valueOf(in));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        //调用完工具类后所有水质指数进行相加总和数据
                        String hkIndex = "0";
                        String hlIndex = "0";
                        String tbhkIndex = "0";
                        String tbhlIndex = "0";
                        if (hkinter != null && hkinter.size() > 0) {
                            String dataValue = segmentFormula.noriverWaterQualityIndex(hkinter);
                            hkIndex = dataValue;
                        }
                        if (hlinter != null && hlinter.size() > 0) {
                            String dataValue = segmentFormula.noriverWaterQualityIndex(hlinter);
                            hlIndex = dataValue;
                        }
                        //[hlIndex 河流水质指数, hlsize 河流数量, hkIndex 湖库水质指数, hksize 湖库数量]
                        String nowindex = segmentFormula.countyIndex(hlIndex, monhlsize, hkIndex, monhksize);
                        if (Double.valueOf(nowindex) > 0) {
                            mapdatamoon.put("waterQualityIndex" + monthi, Double.valueOf(nowindex));
                        } else {
                            mapdatamoon.put("waterQualityIndex" + monthi, null);
                        }

                        if (whetherYOY != null && whetherYOY.equals("1")) {
                            if (tbhkinter != null && tbhkinter.size() > 0) {
                                String dataValue = segmentFormula.noriverWaterQualityIndex(tbhkinter);
                                tbhkIndex = dataValue;
                            }
                            if (tbhlinter != null && tbhlinter.size() > 0) {
                                String dataValue = segmentFormula.noriverWaterQualityIndex(tbhlinter);
                                tbhlIndex = dataValue;
                            }
                            //[hlIndex 河流水质指数, hlsize 河流数量, hkIndex 湖库水质指数, hksize 湖库数量]
                            String tbindex = segmentFormula.countyIndex(tbhlIndex, montbhlsize, tbhkIndex, montbhksize);
                            if (Double.valueOf(tbindex) > 0) {
                                mapdatamoon.put("tbwaterQualityIndex" + monthi, Double.valueOf(tbindex));
                            } else {
                                mapdatamoon.put("tbwaterQualityIndex" + monthi, null);
                            }
                        }
                    }
                }
                Object county = mapdatamoon.get("county");
                if (county != null && !"".equals(county)) {
                    maplist.add(mapdatamoon);
                }
            }
        }

        //计算整体市级的
        Map<String, Object> stringObjectMap = this.ljmonljallcountySectionWaterQualityIndex(map);

        mapdata.put("segmentdata", maplist);
        //市区的数据
        mapdata.put("allsegmentdata", stringObjectMap);

        return mapdata;
    }


    /**
     * 查询宿州不累计的月水质指数
     **/

    public Map<String, Object> allcountySectionWaterQualityIndexses(Map<String, Object> map) {
        Map<String, Object> mapdata = new HashMap<>();//返回值存放
        //修约位数
        DecimalFormat format2 = new DecimalFormat("#.00");
        //获取需要的数据
        //水质等级传一查询出修约需要的数据
        List<Map<String, Object>> hlroundingOffmaps = segmentFormula.wqBasStandardcategory("1", "1");
        //水质等级为三查询出水质指数计算的数据
        List<Map<String, Object>> hlindexmaps = segmentFormula.wqBasStandardcategory("1", "3");
        //水质等级传一查询出修约需要的数据
        List<Map<String, Object>> hkroundingOffmaps = segmentFormula.wqBasStandardcategory("2", "1");
        //水质等级为三查询出水质指数计算的数据
        List<Map<String, Object>> hkindexmaps = segmentFormula.wqBasStandardcategory("2", "3");
        List<String> segmentIds = new ArrayList<>();//断面id
        List<String> assessTypeCodes=new ArrayList<>();
        assessTypeCodes.add("0");
        assessTypeCodes.add("1");
        assessTypeCodes.add("2");
        //341321,341322,341323,341324,341302,341303,341304,341305,341306
        //List<String> countyCodes = (List<String>) map.get("countyCodes");//区划编码
        List<String> countyCodes =new ArrayList<>();//区划编码
        String countyCode1s = ruoYiConfig.getCountyCode();
        Map<String,Object> allpubCodeRegionmap=new HashMap<>();
        allpubCodeRegionmap.put("ParentCode",countyCode1s);
        List<Map<String, Object>> mapList = regionUtliMapper.allpubCodeRegion(allpubCodeRegionmap);
        if(mapList!=null&&mapList.size()>0){
            for(Map<String, Object>  data:mapList){
                Object code = data.get("Code");
                boolean contains = countyCodes.contains(code);
                if(contains){

                }else {
                    countyCodes.add(String.valueOf(code));
                }
            }
        }

        Object dataTime = map.get("dataTime");
        if (countyCodes != null && countyCodes.size() > 0) {
            //如果默认断面id为空 考核类型为空就默认获取全部的断面id
            Map<String, Object> WqBasSegmentNameAllmap = new HashMap<>();
            WqBasSegmentNameAllmap.put("segmentType", "IsManual");
            WqBasSegmentNameAllmap.put("Segmenttype", "RiverSegment");
            WqBasSegmentNameAllmap.put("segmentTypes", "IsManualIsDrink");
            // WqBasSegmentNameAllmap.put("CountyCodes", countyCodes);
            WqBasSegmentNameAllmap.put("AssessTownCode", countyCodes);
            WqBasSegmentNameAllmap.put("dataTime", dataTime);
            if (assessTypeCodes != null && assessTypeCodes.size() > 0) {
                WqBasSegmentNameAllmap.put("assessTypeCode", assessTypeCodes);
                WqBasSegmentNameAllmap.put("Type", "CountyCode");
            }
            List<Map> list = publicToolsMapper.WqBasSegmentNameAlldataTime(WqBasSegmentNameAllmap);
            //List<Map> list = SegmentUtliMapper.WqBasSegmentNameAll(WqBasSegmentNameAllmap);
            if (list != null && list.size() > 0) {
                for (Map<String, Object> data : list) {
                    Object id = data.get("ID");//断面id
                    segmentIds.add(String.valueOf(id));
                }
            }
        }
        Map<String, Object> SegmentIdsksjsdatatimemap = new HashMap<>();
        SegmentIdsksjsdatatimemap.put("dataTime", dataTime);
        SegmentIdsksjsdatatimemap.put("segmentIds", segmentIds);
        SegmentIdsksjsdatatimemap.put("assessTypeCodes", assessTypeCodes);
        Map<String, Object> stringObjectMap = this.SegmentIdsksjsdatatime(SegmentIdsksjsdatatimemap);
        String beginTimes = (String) stringObjectMap.get("beginTime");//当期开始时间 根据传入年份拼接一月份开始

        List<String> cityCodes = countyCodes;//区划
        List<String> monthall = (List<String>) stringObjectMap.get("monthall");//开始时间
        List<Map<String, Object>> ItemIsRiverEvalute = (List<Map<String, Object>>) stringObjectMap.get("ItemIsRiverEvalute");//参与计算因子
        Object whetherYOY = map.get("whetherYOY");//是否展示同比
        Object type = map.get("type");//不为空的话返回所有年份的总均值然后计算总体水质指数
        String beginTime = "";
        if (monthall != null && monthall.size() > 0) {
            int size = monthall.size() - 1;
            beginTime = monthall.get(size);
        }
        List<String> tbmonthall = (List<String>) stringObjectMap.get("tbmonthall");

        //得到对应的数据id进行查询对应均值数据
        //湖库对应断面均值（以区划进行分组）
        //  List<Map<String, Object>> hkmaps = new ArrayList<>();
        List<Map<String, Object>> hkdataall = new ArrayList<>();
        // List<Map<String, Object>> ljhkmaps = new ArrayList<>();
        List<Map<String, Object>> allljhkmaps = new ArrayList<>();
        List<String> hkSegmentIdsone = (List<String>) stringObjectMap.get("hkSegmentIdsone");//断面id
        List<String> hlSegmentIdsone = (List<String>) stringObjectMap.get("hlSegmentIdsone");//断面id

        if (hkSegmentIdsone != null && hkSegmentIdsone.size() > 0) {
            Map<String, Object> hkmanualIndexMonthlyData = new HashMap<>();
            hkmanualIndexMonthlyData.put("SegmentIds", hkSegmentIdsone);
            hkmanualIndexMonthlyData.put("beginTime", beginTimes);
            hkmanualIndexMonthlyData.put("endTime", dataTime);
            hkmanualIndexMonthlyData.put("AssessTownCode", countyCodes);
            hkmanualIndexMonthlyData.put("bussinessCategoryCode", "CBN");
            hkmanualIndexMonthlyData.put("Segmenttype", "hlhkSegment");
            hkmanualIndexMonthlyData.put("SampleDate", "moon");
            // hkmaps = ManualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(hkmanualIndexMonthlyData);
            hkmanualIndexMonthlyData.put("Segmenttype", "Segment");
            //hkmanualIndexMonthlyData.put("SampleCountyCodeDate", "all");
            hkdataall = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(hkmanualIndexMonthlyData);
            hkmanualIndexMonthlyData.put("Segmenttype", "Segment");
            hkmanualIndexMonthlyData.put("SampleDate", "");
            hkmanualIndexMonthlyData.put("SampleCountyCodeDate", "all");
            //   ljhkmaps = ManualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(hkmanualIndexMonthlyData);
            hkmanualIndexMonthlyData.put("SampleCountyCodeDate", "");
            allljhkmaps = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(hkmanualIndexMonthlyData);

        }
        //河流对应断面均值（以区划进行分组）
        List<Map<String, Object>> hldataall = new ArrayList<>();
        List<Map<String, Object>> allljhlmaps = new ArrayList<>();
        if (hlSegmentIdsone != null && hlSegmentIdsone.size() > 0) {
            Map<String, Object> hlmanualIndexMonthlyData = new HashMap<>();
            hlmanualIndexMonthlyData.put("SegmentIds", hlSegmentIdsone);
            hlmanualIndexMonthlyData.put("beginTime", beginTimes);
            hlmanualIndexMonthlyData.put("endTime", dataTime);
            hlmanualIndexMonthlyData.put("AssessTownCode", countyCodes);
            hlmanualIndexMonthlyData.put("bussinessCategoryCode", "CBN");
            hlmanualIndexMonthlyData.put("Segmenttype", "hlhkSegment");
            hlmanualIndexMonthlyData.put("SampleDate", "moon");
            hlmanualIndexMonthlyData.put("Segmenttype", "Segment");
            //hlmanualIndexMonthlyData.put("SampleCountyCodeDate", "all");
            hldataall = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(hlmanualIndexMonthlyData);
            hlmanualIndexMonthlyData.put("Segmenttype", "Segment");
            hlmanualIndexMonthlyData.put("SampleCountyCodeDate", "all");
            hlmanualIndexMonthlyData.put("SampleDate", "");
            hlmanualIndexMonthlyData.put("SampleCountyCodeDate", "");
            allljhlmaps = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(hlmanualIndexMonthlyData);

        }

        //同比数据
        List<Map<String, Object>> tbhkmapsall = new ArrayList<>();
        List<Map<String, Object>> allljtbhkmaps = new ArrayList<>();
        List<Map<String, Object>> tbhlmapsall = new ArrayList<>();
        List<Map<String, Object>> ljtbhkmaps = new ArrayList<>();
        List<Map<String, Object>> ljtbhlmaps = new ArrayList<>();
        List<Map<String, Object>> allljtbhlmaps = new ArrayList<>();
        //湖库对应断面均值（以区划进行分组）
        if (hkSegmentIdsone != null && hkSegmentIdsone.size() > 0) {
            Map<String, Object> tbhkmanualIndexMonthlyData = new HashMap<>();
            tbhkmanualIndexMonthlyData.put("SegmentIds", hkSegmentIdsone);
            tbhkmanualIndexMonthlyData.put("beginTime", stringObjectMap.get("tbksData"));
            tbhkmanualIndexMonthlyData.put("endTime", stringObjectMap.get("tbjsData"));
            tbhkmanualIndexMonthlyData.put("AssessTownCode", countyCodes);
            tbhkmanualIndexMonthlyData.put("Segmenttype", "hlhkSegment");
            tbhkmanualIndexMonthlyData.put("SampleDate", "moon");
            tbhkmanualIndexMonthlyData.put("bussinessCategoryCode", "CBN");
            tbhkmanualIndexMonthlyData.put("Segmenttype", "Segment");
            tbhkmanualIndexMonthlyData.put("SampleCountyCodeDate", "all");
            tbhkmapsall = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(tbhkmanualIndexMonthlyData);
            tbhkmanualIndexMonthlyData.put("Segmenttype", "Segment");
            tbhkmanualIndexMonthlyData.put("SampleDate", "");
            tbhkmanualIndexMonthlyData.put("SampleCountyCodeDate", "all");
            ljtbhkmaps = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(tbhkmanualIndexMonthlyData);
            tbhkmanualIndexMonthlyData.put("SampleCountyCodeDate", "");
            allljtbhkmaps = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(tbhkmanualIndexMonthlyData);

        }
        //河流对应断面均值（以区划进行分组）
        if (hlSegmentIdsone != null && hlSegmentIdsone.size() > 0) {
            Map<String, Object> tbhlmanualIndexMonthlyData = new HashMap<>();
            tbhlmanualIndexMonthlyData.put("SegmentIds", hlSegmentIdsone);
            tbhlmanualIndexMonthlyData.put("beginTime", stringObjectMap.get("tbksData"));
            tbhlmanualIndexMonthlyData.put("endTime", stringObjectMap.get("tbjsData"));
            tbhlmanualIndexMonthlyData.put("AssessTownCode", countyCodes);
            tbhlmanualIndexMonthlyData.put("Segmenttype", "hlhkSegment");
            tbhlmanualIndexMonthlyData.put("SampleDate", "moon");
            tbhlmanualIndexMonthlyData.put("bussinessCategoryCode", "CBN");
            tbhlmanualIndexMonthlyData.put("Segmenttype", "Segment");
            tbhlmapsall = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(tbhlmanualIndexMonthlyData);
            tbhlmanualIndexMonthlyData.put("Segmenttype", "Segment");
            tbhlmanualIndexMonthlyData.put("SampleDate", "");
            tbhlmanualIndexMonthlyData.put("SampleCountyCodeDate", "all");
            ljtbhlmaps = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(tbhlmanualIndexMonthlyData);
            tbhlmanualIndexMonthlyData.put("SampleCountyCodeDate", "");
            allljtbhlmaps = manualComparisonOfWaterQualityMapper.avgmanualIndexMonthlyData(tbhlmanualIndexMonthlyData);

        }


        //对应监测数据均值 同比/当前
        List<Map<String, Object>> hkdata = hkdataall;
        List<Map<String, Object>> hldata = hldataall;
        List<Map<String, Object>> tbhkdata = tbhkmapsall;
        List<Map<String, Object>> tbhldata = tbhlmapsall;
        //累计需要计算的数据
        List<Map<String, Object>> ljhkdata = new ArrayList<>();
        List<Map<String, Object>> ljhldata = new ArrayList<>();
        List<Map<String, Object>> ljtbhkdata = new ArrayList<>();
        List<Map<String, Object>> ljtbhldata = new ArrayList<>();
        if (allljhkmaps != null) {
            ljhkdata = allljhkmaps;
        } else {
            ljhkdata =ljhkdata; //ljhkmaps
        }
        if (allljhlmaps != null ) {
            ljhldata = allljhlmaps;
        } else {
            ljhldata = ljhldata; //ljhkmaps
        }
        if (allljtbhkmaps != null) {
            ljtbhkdata =allljtbhkmaps;
        } else {
            ljtbhkdata = ljtbhkmaps; //ljhkmaps
        }
        if (allljtbhlmaps != null) {
            ljtbhldata =allljtbhlmaps;
        } else {
            ljtbhldata = ljtbhlmaps; //ljhkmaps
        }
        //获取对应id的每个区划不通数据类型的数量
        List<Map<String, Object>> segmentCountysl = (List<Map<String, Object>>) stringObjectMap.get("segmentCountysl");
        List<Map<String, Object>> tbsegmentCountysl = (List<Map<String, Object>>) stringObjectMap.get("tbsegmentCountysl");

        //计算整体市级的
        Map<String, Object> mapdatashi = new HashMap<>();
        Object sementname = map.get("sementname");
        if(sementname!=null&&"1".equals(sementname)){
            mapdatashi.put("riverName", "高平市");
            mapdatashi.put("riverID", "140581");
        }else if(sementname!=null&&"2".equals(sementname)){
            mapdatashi.put("segmentName", "高平市");
            mapdatashi.put("segmentID", "140581");
        }else {
            mapdatashi.put("county", "高平市");
            mapdatashi.put("countyCode", "140581");
        }
        //mapdatashi.put("county", "高平市");
        // mapdatashi.put("countyCode", "140581");
        mapdatashi.put("changeranking", "");
        mapdatashi.put("completed", "true");
        mapdatashi.put("waterQualityIndexranking", "");
        //分组判断，stream流
        //hkCountyCodedata.
        Map<String, List<Map<String, Object>>> ljhkitemdata =
                ljhkdata.stream().collect(
                        Collectors.groupingBy(item -> item.get("ItemCode").toString())
                );
        Map<String, List<Map<String, Object>>> ljhlitemdata =
                ljhldata.stream().collect(
                        Collectors.groupingBy(item -> item.get("ItemCode").toString())
                );
        Map<String, List<Map<String, Object>>> ljtbhkitemdata =
                ljtbhkdata.stream().collect(
                        Collectors.groupingBy(item -> item.get("ItemCode").toString())
                );
        Map<String, List<Map<String, Object>>> ljtbhlitemdata =
                ljtbhldata.stream().collect(
                        Collectors.groupingBy(item -> item.get("ItemCode").toString())
                );

        Map<String, List<Map<String, Object>>> hkitemdata =
                hkdata.stream().collect(
                        Collectors.groupingBy(item -> item.get("ItemCode").toString())
                );
        Map<String, List<Map<String, Object>>> hlitemdata =
                hldata.stream().collect(
                        Collectors.groupingBy(item -> item.get("ItemCode").toString())
                );
        Map<String, List<Map<String, Object>>> tbhkitemdata =
                tbhkdata.stream().collect(
                        Collectors.groupingBy(item -> item.get("ItemCode").toString())
                );
        Map<String, List<Map<String, Object>>> tbhlitemdata =
                tbhldata.stream().collect(
                        Collectors.groupingBy(item -> item.get("ItemCode").toString())
                );
        //根据对应区划处理对应断面id 得到断面id 和断面id数量
        int hksize = 0;
        int hlsize = 0;
        int hlsizess = 0;
        int tbhksize = 0;
        int tbhlsize = 0;

        List<Map<String, Object>> segmentCountyslall = (List<Map<String, Object>>) stringObjectMap.get("segmentCountyslall");
        List<Map<String, Object>> tbsegmentCountyslall = (List<Map<String, Object>>) stringObjectMap.get("tbsegmentCountyslall");

        //cityCodes
        if (cityCodes != null && cityCodes.size() > 0) {
            for (String data : cityCodes) {
                //获取对应区划进行 对区划不同断面数据相加
                if (segmentCountyslall != null && segmentCountyslall.size() > 0) {
                    for (Map<String, Object> datasl : segmentCountyslall) {
                        Object sl = datasl.get("sl");//数量
                        Object countyCode = datasl.get("CountyCode");//区划编码
                        Object segmentCategory = datasl.get("SegmentCategory");//断面类型 1是河流 2湖库
                        Object county = datasl.get("County");//区划名称
                        Object SampleDates = datasl.get("SampleDates");//时间
                        if (SampleDates != null && !"".equals(SampleDates)) {//beginTime
                            if (SampleDates.equals(beginTime)) {
                                if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                                    if (hlsizess < 0) {
                                        hlsizess = Integer.valueOf(String.valueOf(sl));
                                    } else {
                                        hlsizess = hlsizess + Integer.valueOf(String.valueOf(sl));
                                    }
                                }
                            }
                        }
                        if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                            if (countyCode != null && !"".equals(countyCode)) {
                                if (data.equals(String.valueOf(countyCode))) {
                                    hlsize = hlsize + Integer.valueOf(String.valueOf(sl));
                                }
                            }
                        }
                        if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                            if (countyCode != null && !"".equals(countyCode)) {
                                if (data.equals(String.valueOf(countyCode))) {
                                    hksize = hksize + Integer.valueOf(String.valueOf(sl));
                                }
                            }
                        }
                    }


                }
                if (tbsegmentCountyslall != null && tbsegmentCountyslall.size() > 0) {
                    for (Map<String, Object> datasl : tbsegmentCountyslall) {
                        Object sl = datasl.get("sl");//数量
                        Object countyCode = datasl.get("CountyCode");//区划编码
                        Object segmentCategory = datasl.get("SegmentCategory");//断面类型 1是河流 2湖库
                        Object county = datasl.get("County");//区划名称
                        Object SampleDates = datasl.get("SampleDates");//时间
                        if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                            /*if (tbhlsize < Integer.valueOf(String.valueOf(sl))) {
                                tbhlsize = Integer.valueOf(String.valueOf(sl));
                            }*/
                            if (countyCode != null && !"".equals(countyCode)) {
                                if (data.equals(String.valueOf(countyCode))) {
                                    tbhlsize = tbhlsize + Integer.valueOf(String.valueOf(sl));
                                }
                            }
                        }
                        if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                            /*if (tbhksize < Integer.valueOf(String.valueOf(sl))) {
                                tbhksize = Integer.valueOf(String.valueOf(sl));
                            }*/
                            if (countyCode != null && !"".equals(countyCode)) {
                                if (data.equals(String.valueOf(countyCode))) {
                                    tbhksize = tbhksize + Integer.valueOf(String.valueOf(sl));
                                }
                            }
                        }
                    }


                }
            }
        }


        if (ItemIsRiverEvalute != null && ItemIsRiverEvalute.size() > 0) {
            String allhl = "0";
            String allhk = "0";
            String alltbhl = "0";
            String alltbhk = "0";
            List<String> testavghl = new ArrayList<>();
            List<String> testavghk = new ArrayList<>();
            //不累计月份的均值总值数据
            List<String> allavghl = new ArrayList<>();
            List<String> allavghk = new ArrayList<>();
            List<String> allavgtbhl = new ArrayList<>();
            List<String> allavgtbhk = new ArrayList<>();
            for (Map<String, Object> Itemdata : ItemIsRiverEvalute) {
                Object id = Itemdata.get("ID");//获取因子编码
                Object CNName = Itemdata.get("CNName");//获取因子
                //获取修约的标准值
                String roundingOffstandardValue = "0";
                if (hlroundingOffmaps != null && hlroundingOffmaps.size() > 0) {
                    for (Map<String, Object> data : hlroundingOffmaps) {
                        Object standardValue = data.get("StandardValue");//标准值
                        Object itemCodedata = data.get("ItemCode");//因子编码
                        if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                            roundingOffstandardValue = String.valueOf(standardValue);
                        }
                    }
                }
                //获取计算水质指数的标准值
                String indexstandardValue = "0";
                if (hlindexmaps != null && hlindexmaps.size() > 0) {
                    for (Map<String, Object> data : hlindexmaps) {
                        Object standardValue = data.get("StandardValue");//标准值
                        Object itemCodedata = data.get("ItemCode");//因子编码
                        if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                            indexstandardValue = String.valueOf(standardValue);
                        }
                    }
                }

                //获取修约的标准值
                String hkroundingOffstandardValue = "0";
                if (hkroundingOffmaps != null && hkroundingOffmaps.size() > 0) {
                    for (Map<String, Object> data : hkroundingOffmaps) {
                        Object standardValue = data.get("StandardValue");//标准值
                        Object itemCodedata = data.get("ItemCode");//因子编码
                        if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                            hkroundingOffstandardValue = String.valueOf(standardValue);
                        }
                    }
                }
                //获取计算水质指数的标准值
                String hkindexstandardValue = "0";
                if (hkindexmaps != null && hkindexmaps.size() > 0) {
                    for (Map<String, Object> data : hkindexmaps) {
                        Object standardValue = data.get("StandardValue");//标准值
                        Object itemCodedata = data.get("ItemCode");//因子编码
                        if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                            hkindexstandardValue = String.valueOf(standardValue);
                        }
                    }
                }
                List<Map<String, Object>> hkmaps = ljhkitemdata.get(id);
                List<Map<String, Object>> hlmaps = ljhlitemdata.get(id);
                List<Map<String, Object>> tbhkmaps = ljtbhkitemdata.get(id);
                List<Map<String, Object>> tbhlmaps = ljtbhlitemdata.get(id);
                List<String> avghl = new ArrayList<>();

                List<String> avghk = new ArrayList<>();
                List<String> avgtbhl = new ArrayList<>();
                List<String> avgtbhk = new ArrayList<>();
                if (hkmaps != null && hkmaps.size() > 0) {
                    for (Map<String, Object> hkmapsdata : hkmaps) {
                        Object effectiveValues = hkmapsdata.get("EffectiveValue");
                        String effectiveValue = null;
                        //判断是否科学计算法，如果是就进行转换
                        boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                        if (scientificNotation) {
                            BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                            String effectiveValuesdatas = bigDecimal.toPlainString();
                            effectiveValue = effectiveValuesdatas;
                        } else {
                            effectiveValue = String.valueOf(effectiveValues);
                        }
                        Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                        Object SampleDates = hkmapsdata.get("SampleDates");
                        if (effectiveValue != null && !"".equals(effectiveValue)) {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("2")) {
                                avghk.add(String.valueOf(effectiveValue));
                            }
                        }
                    }
                }
                if (hlmaps != null && hlmaps.size() > 0) {
                    for (Map<String, Object> hkmapsdata : hlmaps) {
                        Object effectiveValues = hkmapsdata.get("EffectiveValue");
                        Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                        Object SampleDates = hkmapsdata.get("SampleDates");
                        String effectiveValue = null;
                        //判断是否科学计算法，如果是就进行转换
                        boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                        if (scientificNotation) {
                            BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                            String effectiveValuesdatas = bigDecimal.toPlainString();
                            effectiveValue = effectiveValuesdatas;
                        } else {
                            effectiveValue = String.valueOf(effectiveValues);
                        }
                        if (effectiveValue != null && !"".equals(effectiveValue)) {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("1")) {
                                avghl.add(String.valueOf(effectiveValue));
                            }
                        }
                    }
                }
                if (tbhkmaps != null && tbhkmaps.size() > 0) {
                    for (Map<String, Object> hkmapsdata : tbhkmaps) {
                        Object effectiveValues = hkmapsdata.get("EffectiveValue");
                        String effectiveValue = null;
                        //判断是否科学计算法，如果是就进行转换
                        boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                        if (scientificNotation) {
                            BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                            String effectiveValuesdatas = bigDecimal.toPlainString();
                            effectiveValue = effectiveValuesdatas;
                        } else {
                            effectiveValue = String.valueOf(effectiveValues);
                        }
                        Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                        Object SampleDates = hkmapsdata.get("SampleDates");
                        if (effectiveValue != null && !"".equals(effectiveValue)) {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("2")) {
                                avgtbhk.add(String.valueOf(effectiveValue));
                            }
                        }
                    }
                }
                if (tbhlmaps != null && tbhlmaps.size() > 0) {
                    for (Map<String, Object> hkmapsdata : tbhlmaps) {
                        Object effectiveValues = hkmapsdata.get("EffectiveValue");
                        String effectiveValue = null;
                        //判断是否科学计算法，如果是就进行转换
                        boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                        if (scientificNotation) {
                            BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                            String effectiveValuesdatas = bigDecimal.toPlainString();
                            effectiveValue = effectiveValuesdatas;
                        } else {
                            effectiveValue = String.valueOf(effectiveValues);
                        }
                        Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                        Object SampleDates = hkmapsdata.get("SampleDates");
                        if (effectiveValue != null && !"".equals(effectiveValue)) {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("1")) {
                                avgtbhl.add(String.valueOf(effectiveValue));
                            }
                        }
                    }
                }
                //计算月份的水质指数
                if (CNName != null && !"".equals(CNName)) {
                    if (avghl != null && avghl.size() > 0) {
                        String dataValue = SegmentFormula.avgdata(avghl);
                        //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                        Map maplistData = this.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(id), "", "1", "", "", String.valueOf(dataValue));
                        if (maplistData != null && maplistData.size() > 0) {
                            Object v = maplistData.get("_V"); //修约后的值
                            Object in = maplistData.get("_IN");//单个因子的指数
                            testavghl.add(String.valueOf(v));
                            if (in != null && !"".equals(in)) {
                                //数据计算总和得到河流/湖库/断面指数总和
                                allavghl.add(String.valueOf(in));
                            }
                        }
                    }
                    if (avghk != null && avghk.size() > 0) {
                        String dataValue = SegmentFormula.avgdata(avghk);
                        //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                        Map maplistData = this.itemDataINV(hkindexstandardValue, hkroundingOffstandardValue, String.valueOf(id), "", "2", "", "", String.valueOf(dataValue));
                        if (maplistData != null && maplistData.size() > 0) {
                            Object v = maplistData.get("_V"); //修约后的值
                            Object in = maplistData.get("_IN");//单个因子的指数
                            testavghk.add(String.valueOf(v));
                            if (in != null && !"".equals(in)) {
                                //数据计算总和得到河流/湖库/断面指数总和
                                allavghk.add(String.valueOf(in));
                            }
                        }
                    }
                    if (avgtbhl != null && avgtbhl.size() > 0) {
                        String dataValue = SegmentFormula.avgdata(avgtbhl);
                        //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                        Map maplistData = this.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(id), "", "1", "", "", String.valueOf(dataValue));
                        if (maplistData != null && maplistData.size() > 0) {
                            Object v = maplistData.get("_V"); //修约后的值
                            Object in = maplistData.get("_IN");//单个因子的指数
                            if (in != null && !"".equals(in)) {
                                //数据计算总和得到河流/湖库/断面指数总和
                                allavgtbhl.add(String.valueOf(in));
                            }
                        }
                    }
                    if (avgtbhk != null && avgtbhk.size() > 0) {
                        String dataValue = SegmentFormula.avgdata(avgtbhk);
                        //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                        Map maplistData = this.itemDataINV(hkindexstandardValue, hkroundingOffstandardValue, String.valueOf(id), "", "2", "", "", String.valueOf(dataValue));
                        if (maplistData != null && maplistData.size() > 0) {
                            Object v = maplistData.get("_V"); //修约后的值
                            Object in = maplistData.get("_IN");//单个因子的指数
                            if (in != null && !"".equals(in)) {
                                //数据计算总和得到河流/湖库/断面指数总和
                                allavgtbhk.add(String.valueOf(in));
                            }
                        }
                    }

                }
            }

            //调用完工具类后所有水质指数进行相加总和数据
            if (allavghl != null && allavghl.size() > 0) {
                String dataValue = segmentFormula.noriverWaterQualityIndex(allavghl);
                allhl = dataValue;
            }
            if (allavghk != null && allavghk.size() > 0) {
                String dataValue = segmentFormula.noriverWaterQualityIndex(allavghk);
                allhk = dataValue;
            }
            //System.out.println(testavghl);
            //System.out.println(testavghk);
            //hlIndex 河流水质指数, hlsize 河流数量, hkIndex 湖库水质指数, hksize 湖库数量
            String index = segmentFormula.countyIndex(allhl, hlsize, allhk, hksize);
            if (Double.valueOf(index) > 0) {
                mapdatashi.put("waterQualityIndex", Double.valueOf(index));
            } else {
                mapdatashi.put("waterQualityIndex", null);
            }

            if (allavgtbhl != null && allavgtbhl.size() > 0) {
                String dataValue = segmentFormula.noriverWaterQualityIndex(allavgtbhl);
                alltbhl = dataValue;
            }
            if (allavgtbhk != null && allavgtbhk.size() > 0) {
                String dataValue = segmentFormula.noriverWaterQualityIndex(allavgtbhk);
                alltbhk = dataValue;
            }
            //hlIndex 河流水质指数, hlsize 河流数量, hkIndex 湖库水质指数, hksize 湖库数量
            String tbindex = segmentFormula.countyIndex(alltbhl, tbhlsize, alltbhk, tbhksize);
            if (Double.valueOf(tbindex) > 0) {
                mapdatashi.put("tbwaterQualityIndex", Double.valueOf(tbindex));
            } else {
                mapdatashi.put("tbwaterQualityIndex", null);
            }
            //计算变换率 （年达标率-上年达标率）/上年达标率
            if (index != null && tbindex != null && Double.valueOf(index) > 0 && Double.valueOf(tbindex) > 0 && !"0".equals(String.valueOf(index)) && !"0".equals(String.valueOf(tbindex))) {
                Double v = Double.valueOf(index) - Double.valueOf(tbindex);
                Double v1 = v / Double.valueOf(tbindex) * 100;
                mapdatashi.put("change", Double.valueOf(format2.format(v1)));
            } else {
                mapdatashi.put("change", null);
            }
        }
        //当期月的
        if (monthall != null && monthall.size() > 0) {
            for (String monthalldata : monthall) {
                if (ItemIsRiverEvalute != null && ItemIsRiverEvalute.size() > 0) {
                    String allhl = "0";
                    String allhk = "0";
                    int hksizes = 0; //湖库断面id数量
                    int hlsizes = 0; //河流断面id数量
                    if (cityCodes != null && cityCodes.size() > 0) {
                        for (String data : cityCodes) {
                            if (segmentCountysl != null && segmentCountysl.size() > 0) {
                                for (Map<String, Object> datasl : segmentCountysl) {
                                    Object sl = datasl.get("sl");//数量
                                    Object countyCode = datasl.get("CountyCode");//区划编码
                                    Object segmentCategory = datasl.get("SegmentCategory");//断面类型 1是河流 2湖库
                                    Object county = datasl.get("County");//区划名称
                                    Object SampleDates = datasl.get("SampleDates");//监测时间
                                    if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                                        if (SampleDates != null && SampleDates.equals(monthalldata)) {
                                            if (countyCode != null && !"".equals(countyCode)) {
                                                if (data.equals(String.valueOf(countyCode))) {
                                                    if (hlsizes == 0) {
                                                        hlsizes = Integer.valueOf(String.valueOf(sl));
                                                    } else {
                                                        hlsizes = hlsizes + Integer.valueOf(String.valueOf(sl));
                                                    }
                                                }
                                            }


                                        }
                                    }
                                    if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                                        if (SampleDates != null && SampleDates.equals(monthalldata)) {
                                            if (countyCode != null && !"".equals(countyCode)) {
                                                if (data.equals(String.valueOf(countyCode))) {
                                                    if (hlsizes == 0) {
                                                        hksizes = Integer.valueOf(String.valueOf(sl));
                                                    } else {
                                                        hksizes = hksizes + Integer.valueOf(String.valueOf(sl));
                                                    }
                                                }
                                            }


                                        }
                                    }
                                }
                            }
                        }
                    }


                    //不累计月份的均值总值数据
                    List<String> allavghl = new ArrayList<>();
                    List<String> allavghls = new ArrayList<>();
                    List<String> allavghk = new ArrayList<>();
                    List<String> allavghks = new ArrayList<>();
                    for (Map<String, Object> Itemdata : ItemIsRiverEvalute) {
                        Object id = Itemdata.get("ID");//获取因子编码
                        Object CNName = Itemdata.get("CNName");//获取因子
                        //获取修约的标准值
                        String roundingOffstandardValue = "0";
                        if (hlroundingOffmaps != null && hlroundingOffmaps.size() > 0) {
                            for (Map<String, Object> data : hlroundingOffmaps) {
                                Object standardValue = data.get("StandardValue");//标准值
                                Object itemCodedata = data.get("ItemCode");//因子编码
                                if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                    roundingOffstandardValue = String.valueOf(standardValue);
                                }
                            }
                        }
                        //获取计算水质指数的标准值
                        String indexstandardValue = "0";
                        if (hlindexmaps != null && hlindexmaps.size() > 0) {
                            for (Map<String, Object> data : hlindexmaps) {
                                Object standardValue = data.get("StandardValue");//标准值
                                Object itemCodedata = data.get("ItemCode");//因子编码
                                if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                    indexstandardValue = String.valueOf(standardValue);
                                }
                            }
                        }
                        //获取修约的标准值
                        String hkroundingOffstandardValue = "0";
                        if (hkroundingOffmaps != null && hkroundingOffmaps.size() > 0) {
                            for (Map<String, Object> data : hkroundingOffmaps) {
                                Object standardValue = data.get("StandardValue");//标准值
                                Object itemCodedata = data.get("ItemCode");//因子编码
                                if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                    hkroundingOffstandardValue = String.valueOf(standardValue);
                                }
                            }
                        }
                        //获取计算水质指数的标准值
                        String hkindexstandardValue = "0";
                        if (hkindexmaps != null && hkindexmaps.size() > 0) {
                            for (Map<String, Object> data : hkindexmaps) {
                                Object standardValue = data.get("StandardValue");//标准值
                                Object itemCodedata = data.get("ItemCode");//因子编码
                                if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                    hkindexstandardValue = String.valueOf(standardValue);
                                }
                            }
                        }
                        List<Map<String, Object>> hkmaps = hkitemdata.get(id);
                        List<Map<String, Object>> hlmaps = hlitemdata.get(id);
                        List<String> avghl = new ArrayList<>();
                        List<String> avghk = new ArrayList<>();
                        if (hkmaps != null && hkmaps.size() > 0) {
                            for (Map<String, Object> hkmapsdata : hkmaps) {
                                Object effectiveValues = hkmapsdata.get("EffectiveValue");
                                String effectiveValue = null;
                                //判断是否科学计算法，如果是就进行转换
                                boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                                if (scientificNotation) {
                                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                                    String effectiveValuesdatas = bigDecimal.toPlainString();
                                    effectiveValue = effectiveValuesdatas;
                                } else {
                                    effectiveValue = String.valueOf(effectiveValues);
                                }
                                Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                                Object SampleDates = hkmapsdata.get("SampleDates");
                                if (SampleDates != null && SampleDates.equals(monthalldata) && effectiveValue != null && !"".equals(effectiveValue)) {
                                    if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("2")) {
                                        avghk.add(String.valueOf(effectiveValue));
                                    }
                                }
                            }
                        }
                        if (hlmaps != null && hlmaps.size() > 0) {
                            for (Map<String, Object> hkmapsdata : hlmaps) {
                                Object effectiveValues = hkmapsdata.get("EffectiveValue");
                                String effectiveValue = null;
                                //判断是否科学计算法，如果是就进行转换
                                boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                                if (scientificNotation) {
                                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                                    String effectiveValuesdatas = bigDecimal.toPlainString();
                                    effectiveValue = effectiveValuesdatas;
                                } else {
                                    effectiveValue = String.valueOf(effectiveValues);
                                }
                                Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                                Object SampleDates = hkmapsdata.get("SampleDates");
                                if (SampleDates != null && SampleDates.equals(monthalldata) && effectiveValue != null && !"".equals(effectiveValue)) {
                                    if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("1")) {
                                        avghl.add(String.valueOf(effectiveValue));
                                    }
                                }
                            }
                        }

                        //计算月份的水质指数
                        if (CNName != null && !"".equals(CNName)) {
                            if (avghl != null && avghl.size() > 0) {
                                String dataValue = SegmentFormula.avgdata(avghl);
                                //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                                Map maplistData = this.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(id), "", "1", "", "", String.valueOf(dataValue));
                                if (maplistData != null && maplistData.size() > 0) {
                                    Object v = maplistData.get("_V"); //修约后的值
                                    Object in = maplistData.get("_IN");//单个因子的指数
                                    allavghls.add(String.valueOf(v));
                                    if (in != null && !"".equals(in)) {
                                        //数据计算总和得到河流/湖库/断面指数总和
                                        allavghl.add(String.valueOf(in));
                                    }
                                }
                            }
                            if (avghk != null && avghk.size() > 0) {
                                String dataValue = SegmentFormula.avgdata(avghk);
                                //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                                Map maplistData = this.itemDataINV(hkindexstandardValue, hkroundingOffstandardValue, String.valueOf(id), "", "2", "", "", String.valueOf(dataValue));
                                if (maplistData != null && maplistData.size() > 0) {
                                    Object v = maplistData.get("_V"); //修约后的值
                                    Object in = maplistData.get("_IN");//单个因子的指数
                                    allavghks.add(String.valueOf(v));
                                    if (in != null && !"".equals(in)) {
                                        //数据计算总和得到河流/湖库/断面指数总和
                                        allavghk.add(String.valueOf(in));
                                    }
                                }
                            }

                        }
                    }

                    //调用完工具类后所有水质指数进行相加总和数据
                    if (allavghl != null && allavghl.size() > 0) {
                        String dataValue = segmentFormula.noriverWaterQualityIndex(allavghl);
                        allhl = dataValue;
                    }
                    if (allavghk != null && allavghk.size() > 0) {
                        String dataValue = segmentFormula.noriverWaterQualityIndex(allavghk);
                        allhk = dataValue;
                    }
                    // System.out.println(allavghls);
                    // System.out.println(allavghks);
                    //hlIndex 河流水质指数, hlsize 河流数量, hkIndex 湖库水质指数, hksize 湖库数量
                    //String index = SegmentFormula.countyIndex(allhl, hlsizes, allhk, hksizes);
                   /* if (allhk != null && !"0".equals(allhk)) {

                    } else {
                        hksize = 0;
                    }*/
                    String index = segmentFormula.countyIndex(allhl, hlsizes, allhk, hksizes);
                    SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM");
                    Calendar tbcalendar = Calendar.getInstance();
                    try {
                        tbcalendar.setTime(dfs.parse(String.valueOf(monthalldata)));
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    int tbmonth = tbcalendar.get(Calendar.MONTH);
                    int monthi = tbmonth + 1;
                    if (Double.valueOf(index) > 0) {
                        mapdatashi.put("waterQualityIndex" + monthi, Double.valueOf(index));
                    } else {
                        mapdatashi.put("waterQualityIndex" + monthi, null);
                    }


                }
            }
        }
        //判断是否需要同比数据
        if (whetherYOY != null && whetherYOY.equals("1")) {
            for (String monthalldata : tbmonthall) {
                if (ItemIsRiverEvalute != null && ItemIsRiverEvalute.size() > 0) {
                    String alltbhl = "0";
                    String alltbhk = "0";
                    int tbhksizes = 0; //湖库断面id数量
                    int tbhlsizes = 0; //河流断面id数量
                    if (tbsegmentCountysl != null && tbsegmentCountysl.size() > 0) {
                        for (Map<String, Object> datasl : tbsegmentCountysl) {
                            Object sl = datasl.get("sl");//数量
                            Object countyCode = datasl.get("CountyCode");//区划编码
                            Object segmentCategory = datasl.get("SegmentCategory");//断面类型 1是河流 2湖库
                            Object county = datasl.get("County");//区划名称
                            Object SampleDates = datasl.get("SampleDates");//监测时间
                            if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                                if (SampleDates != null && SampleDates.equals(monthalldata)) {
                                    if (tbhlsizes == 0) {
                                        tbhlsizes = Integer.valueOf(String.valueOf(sl));
                                    } else {
                                        tbhlsizes = tbhlsizes + Integer.valueOf(String.valueOf(sl));
                                    }

                                }
                            }
                            if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                                if (SampleDates != null && SampleDates.equals(monthalldata)) {
                                    if (tbhksizes == 0) {
                                        tbhksizes = Integer.valueOf(String.valueOf(sl));
                                    } else {
                                        tbhksizes = tbhksizes + Integer.valueOf(String.valueOf(sl));
                                    }

                                }
                            }
                        }

                    }
                    //不累计月份的均值总值数据
                    List<String> allavgtbhl = new ArrayList<>();
                    List<String> allavgtbhk = new ArrayList<>();
                    for (Map<String, Object> Itemdata : ItemIsRiverEvalute) {
                        Object id = Itemdata.get("ID");//获取因子编码
                        Object CNName = Itemdata.get("CNName");//获取因子
                        //获取修约的标准值
                        String roundingOffstandardValue = "0";
                        if (hlroundingOffmaps != null && hlroundingOffmaps.size() > 0) {
                            for (Map<String, Object> data : hlroundingOffmaps) {
                                Object standardValue = data.get("StandardValue");//标准值
                                Object itemCodedata = data.get("ItemCode");//因子编码
                                if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                    roundingOffstandardValue = String.valueOf(standardValue);
                                }
                            }
                        }
                        //获取计算水质指数的标准值
                        String indexstandardValue = "0";
                        if (hlindexmaps != null && hlindexmaps.size() > 0) {
                            for (Map<String, Object> data : hlindexmaps) {
                                Object standardValue = data.get("StandardValue");//标准值
                                Object itemCodedata = data.get("ItemCode");//因子编码
                                if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                    indexstandardValue = String.valueOf(standardValue);
                                }
                            }
                        }
                        //获取修约的标准值
                        String hkroundingOffstandardValue = "0";
                        if (hkroundingOffmaps != null && hkroundingOffmaps.size() > 0) {
                            for (Map<String, Object> data : hkroundingOffmaps) {
                                Object standardValue = data.get("StandardValue");//标准值
                                Object itemCodedata = data.get("ItemCode");//因子编码
                                if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                    hkroundingOffstandardValue = String.valueOf(standardValue);
                                }
                            }
                        }
                        //获取计算水质指数的标准值
                        String hkindexstandardValue = "0";
                        if (hkindexmaps != null && hkindexmaps.size() > 0) {
                            for (Map<String, Object> data : hkindexmaps) {
                                Object standardValue = data.get("StandardValue");//标准值
                                Object itemCodedata = data.get("ItemCode");//因子编码
                                if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                    hkindexstandardValue = String.valueOf(standardValue);
                                }
                            }
                        }
                        List<Map<String, Object>> tbhkmaps = tbhkitemdata.get(id);
                        List<Map<String, Object>> tbhlmaps = tbhlitemdata.get(id);
                        List<String> avgtbhl = new ArrayList<>();
                        List<String> avgtbhk = new ArrayList<>();
                        if (tbhkmaps != null && tbhkmaps.size() > 0) {
                            for (Map<String, Object> hkmapsdata : tbhkmaps) {
                                Object effectiveValues = hkmapsdata.get("EffectiveValue");
                                String effectiveValue = null;
                                //判断是否科学计算法，如果是就进行转换
                                boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                                if (scientificNotation) {
                                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                                    String effectiveValuesdatas = bigDecimal.toPlainString();
                                    effectiveValue = effectiveValuesdatas;
                                } else {
                                    effectiveValue = String.valueOf(effectiveValues);
                                }
                                Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                                Object SampleDates = hkmapsdata.get("SampleDates");
                                if (SampleDates != null && SampleDates.equals(monthalldata) && effectiveValue != null && !"".equals(effectiveValue)) {
                                    if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("2")) {
                                        avgtbhk.add(String.valueOf(effectiveValue));
                                    }
                                }
                            }
                        }
                        if (tbhlmaps != null && tbhlmaps.size() > 0) {
                            for (Map<String, Object> hkmapsdata : tbhlmaps) {
                                Object effectiveValues = hkmapsdata.get("EffectiveValue");
                                String effectiveValue = null;
                                //判断是否科学计算法，如果是就进行转换
                                boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                                if (scientificNotation) {
                                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                                    String effectiveValuesdatas = bigDecimal.toPlainString();
                                    effectiveValue = effectiveValuesdatas;
                                } else {
                                    effectiveValue = String.valueOf(effectiveValues);
                                }
                                Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                                Object SampleDates = hkmapsdata.get("SampleDates");
                                if (SampleDates != null && SampleDates.equals(monthalldata) && effectiveValue != null && !"".equals(effectiveValue)) {
                                    if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("1")) {
                                        avgtbhl.add(String.valueOf(effectiveValue));
                                    }
                                }
                            }
                        }
                        //计算月份的水质指数
                        if (CNName != null && !"".equals(CNName)) {
                            if (avgtbhl != null && avgtbhl.size() > 0) {
                                String dataValue = SegmentFormula.avgdata(avgtbhl);
                                //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                                Map maplistData = this.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(id), "", "1", "", "", String.valueOf(dataValue));
                                if (maplistData != null && maplistData.size() > 0) {
                                    Object v = maplistData.get("_V"); //修约后的值
                                    Object in = maplistData.get("_IN");//单个因子的指数
                                    if (in != null && !"".equals(in)) {
                                        //数据计算总和得到河流/湖库/断面指数总和
                                        allavgtbhl.add(String.valueOf(in));
                                    }
                                }
                            }
                            if (avgtbhk != null && avgtbhk.size() > 0) {
                                String dataValue = SegmentFormula.avgdata(avgtbhk);
                                //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                                Map maplistData = this.itemDataINV(hkindexstandardValue, hkroundingOffstandardValue, String.valueOf(id), "", "2", "", "", String.valueOf(dataValue));
                                if (maplistData != null && maplistData.size() > 0) {
                                    Object v = maplistData.get("_V"); //修约后的值
                                    Object in = maplistData.get("_IN");//单个因子的指数
                                    if (in != null && !"".equals(in)) {
                                        //数据计算总和得到河流/湖库/断面指数总和
                                        allavgtbhk.add(String.valueOf(in));
                                    }
                                }
                            }

                        }
                    }

                    //调用完工具类后所有水质指数进行相加总和数据
                    if (allavgtbhl != null && allavgtbhl.size() > 0) {
                        String dataValue = segmentFormula.noriverWaterQualityIndex(allavgtbhl);
                        alltbhl = dataValue;
                    }
                    if (allavgtbhk != null && allavgtbhk.size() > 0) {
                        String dataValue = segmentFormula.noriverWaterQualityIndex(allavgtbhk);
                        alltbhk = dataValue;
                    }
                    //hlIndex 河流水质指数, hlsize 河流数量, hkIndex 湖库水质指数, hksize 湖库数量
                    //String tbindex = SegmentFormula.countyIndex(alltbhl, tbhlsizes, alltbhk, tbhksizes);
                    if (alltbhk != null && !"0".equals(alltbhk)) {

                    } else {
                        tbhksize = 0;
                    }
                    String tbindex = segmentFormula.countyIndex(alltbhl, tbhlsize, alltbhk, tbhksize);
                    SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM");
                    Calendar tbcalendar = Calendar.getInstance();
                    try {
                        tbcalendar.setTime(dfs.parse(String.valueOf(monthalldata)));
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    int tbmonth = tbcalendar.get(Calendar.MONTH);
                    int monthi = tbmonth + 1;
                    if (Double.valueOf(tbindex) > 0) {
                        mapdatashi.put("tbwaterQualityIndex" + monthi, Double.valueOf(tbindex));
                    } else {
                        mapdatashi.put("tbwaterQualityIndex" + monthi, null);
                    }

                }
            }
        }

        return mapdatashi;
    }

    public Map<String, Object> ljmonljallcountySectionWaterQualityIndex(Map<String, Object> map) {
        String maxSampleDate = busMonthlycumulativedataMapper.getbasicevaluatedatamaxSampleDate();
        Map<String, Object> mapdata = new HashMap<>();//返回值存放
        //修约位数
        DecimalFormat format2 = new DecimalFormat("#.00");
        //获取需要的数据
        //水质等级传一查询出修约需要的数据
        List<Map<String, Object>> hlroundingOffmaps = segmentFormula.wqBasStandardcategory("1", "1");
        //水质等级为三查询出水质指数计算的数据
        List<Map<String, Object>> hlindexmaps = segmentFormula.wqBasStandardcategory("1", "3");
        //水质等级传一查询出修约需要的数据
        List<Map<String, Object>> hkroundingOffmaps = segmentFormula.wqBasStandardcategory("2", "1");
        //水质等级为三查询出水质指数计算的数据
        List<String> segmentIds = new ArrayList<>();//断面id
        List<String> assessTypeCodes=new ArrayList<>();
        assessTypeCodes.add("0");
        assessTypeCodes.add("1");
        assessTypeCodes.add("2");

        String countyCode1s = ruoYiConfig.getCountyCode();
        Map<String,Object> allpubCodeRegionmap=new HashMap<>();
        allpubCodeRegionmap.put("ParentCode",countyCode1s);
        List<Map<String, Object>> mapList = regionUtliMapper.allpubCodeRegion(allpubCodeRegionmap);
        List<String> countyCodes =new ArrayList<>();//区划编码
        if(mapList!=null&&mapList.size()>0){
            for(Map<String, Object>  data:mapList){
                Object code = data.get("Code");
                boolean contains = countyCodes.contains(code);
                if(contains){

                }else {
                    countyCodes.add(String.valueOf(code));
                }
            }
        }
        Object dataTime = map.get("dataTime");
        if (countyCodes != null && countyCodes.size() > 0) {
            //如果默认断面id为空 考核类型为空就默认获取全部的断面id
            Map<String, Object> WqBasSegmentNameAllmap = new HashMap<>();
            WqBasSegmentNameAllmap.put("segmentType", "IsManual");
            WqBasSegmentNameAllmap.put("Segmenttype", "RiverSegment");
            WqBasSegmentNameAllmap.put("segmentTypes", "IsManualIsDrink");
            // WqBasSegmentNameAllmap.put("CountyCodes", countyCodes);
            WqBasSegmentNameAllmap.put("AssessTownCode", countyCodes);
            WqBasSegmentNameAllmap.put("dataTime", dataTime);
            if (assessTypeCodes != null && assessTypeCodes.size() > 0) {
                WqBasSegmentNameAllmap.put("assessTypeCode", assessTypeCodes);
                WqBasSegmentNameAllmap.put("Type", "CountyCode");
            }
            List<Map> list = publicToolsMapper.WqBasSegmentNameAlldataTime(WqBasSegmentNameAllmap);
            //List<Map> list = SegmentUtliMapper.WqBasSegmentNameAll(WqBasSegmentNameAllmap);
            if (list != null && list.size() > 0) {
                for (Map<String, Object> data : list) {
                    Object id = data.get("ID");//断面id
                    segmentIds.add(String.valueOf(id));
                }
            }
        }
        List<Map<String, Object>> hkindexmaps = segmentFormula.wqBasStandardcategory("2", "3");
        Map<String, Object> SegmentIdsksjsdatatimemap = new HashMap<>();
        SegmentIdsksjsdatatimemap.put("dataTime", dataTime);
        SegmentIdsksjsdatatimemap.put("segmentIds", segmentIds);
        SegmentIdsksjsdatatimemap.put("assessTypeCodes", assessTypeCodes);
        Map<String, Object> stringObjectMap = this.SegmentIdsksjsdatatime(SegmentIdsksjsdatatimemap);
        List<String> cityCodes = countyCodes;//区划
        List<String> monthall = (List<String>) stringObjectMap.get("monthall");//开始时间
        List<Map<String, Object>> ItemIsRiverEvalute = (List<Map<String, Object>>) stringObjectMap.get("ItemIsRiverEvalute");//参与计算因子
        Object whetherYOY = map.get("whetherYOY");//是否展示同比
        Object type = map.get("type");//不为空的话返回所有年份的总均值然后计算总体水质指数
        List<String> tbmonthall = (List<String>) stringObjectMap.get("tbmonthall");
        // List<String> assessTypeCodes = (List<String>) map.get("assessTypeCodes");//考核
        List<String> hkSegmentIdsone = (List<String>) stringObjectMap.get("hkSegmentIdsone");//断面id
        List<String> hlSegmentIdsone = (List<String>) stringObjectMap.get("hlSegmentIdsone");//断面id

        //对应监测数据均值 同比/当前

        //获取月份条数
        int monthallsize = monthall.size();
        int tbmonthallsize = tbmonthall.size();
        //先判断传入的区划为空吗
        //需要调用sql语句进行查询均值然后计算数据
        //获取当前传入时间最大时间
        String nowDataTime = monthall.get(monthallsize - 1);
        if(nowDataTime!=null&&!"".equals(nowDataTime)){
            SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM");
            int i = maxSampleDate.compareTo(nowDataTime);
            System.out.println(i);
            if(i<0){
                nowDataTime=maxSampleDate;
            }

            //maxSampleDate
        }
        Integer year = DateUtils.getYear(nowDataTime, "yyyy-mm");
        //获取同比最大时间
        String tbDataTime = tbmonthall.get(tbmonthallsize - 1);
        Integer tbyear = DateUtils.getYear(tbDataTime, "yyyy-mm");
        List<Map<String, Object>> hkdata = new ArrayList<>();
        if (hkSegmentIdsone != null && hkSegmentIdsone.size() > 0) {
            Map<String, Object> hkmanualIndexMonthlyDatamap = new HashMap<>();
            hkmanualIndexMonthlyDatamap.put("DataType", "5");
            hkmanualIndexMonthlyDatamap.put("beginTime", year + "-01");
            hkmanualIndexMonthlyDatamap.put("endTime", nowDataTime);
            hkmanualIndexMonthlyDatamap.put("SegmentIDs", hkSegmentIdsone);
            hkmanualIndexMonthlyDatamap.put("datatype", "allCountyCode");//根据区划和因子分组查询
            hkmanualIndexMonthlyDatamap.put("datatypes", "CountyCode");//根据区划和因子分组查询
            //湖库均值数据
            hkdata = busMonthlycumulativedataMapper.manualIndexMonthlyData(hkmanualIndexMonthlyDatamap);

        }
        Map<String, Object> hlmanualIndexMonthlyDatamap = new HashMap<>();
        hlmanualIndexMonthlyDatamap.put("DataType", "5");
        hlmanualIndexMonthlyDatamap.put("beginTime", year + "-01");
        hlmanualIndexMonthlyDatamap.put("endTime", nowDataTime);
        hlmanualIndexMonthlyDatamap.put("SegmentIDs", hlSegmentIdsone);
        hlmanualIndexMonthlyDatamap.put("datatype", "allCountyCode");//根据区划和因子分组查询
        hlmanualIndexMonthlyDatamap.put("datatypes", "CountyCode");//根据区划和因子分组查询
        //河流均值数据
        List<Map<String, Object>> hldata = busMonthlycumulativedataMapper.manualIndexMonthlyData(hlmanualIndexMonthlyDatamap);

        //同比数据
        List<Map<String, Object>> tbhkdata = new ArrayList<>();
        if (hkSegmentIdsone != null && hkSegmentIdsone.size() > 0) {
            Map<String, Object> tbhkmanualIndexMonthlyDatamap = new HashMap<>();
            tbhkmanualIndexMonthlyDatamap.put("DataType", "5");
            tbhkmanualIndexMonthlyDatamap.put("beginTime", tbyear + "-01");
            tbhkmanualIndexMonthlyDatamap.put("endTime", tbDataTime);
            tbhkmanualIndexMonthlyDatamap.put("SegmentIDs", hkSegmentIdsone);
            tbhkmanualIndexMonthlyDatamap.put("datatype", "allCountyCode");//根据区划和因子分组查询
            tbhkmanualIndexMonthlyDatamap.put("datatypes", "CountyCode");//根据区划和因子分组查询
            //湖库均值数据
            tbhkdata = busMonthlycumulativedataMapper.manualIndexMonthlyData(tbhkmanualIndexMonthlyDatamap);

        }
        Map<String, Object> tbhlmanualIndexMonthlyDatamap = new HashMap<>();
        tbhlmanualIndexMonthlyDatamap.put("DataType", "5");
        tbhlmanualIndexMonthlyDatamap.put("beginTime", tbyear + "-01");
        tbhlmanualIndexMonthlyDatamap.put("endTime", tbDataTime);
        tbhlmanualIndexMonthlyDatamap.put("SegmentIDs", hlSegmentIdsone);
        tbhlmanualIndexMonthlyDatamap.put("datatype", "allCountyCode");//根据区划和因子分组查询
        tbhlmanualIndexMonthlyDatamap.put("datatypes", "CountyCode");//根据区划和因子分组查询
        //河流均值数据
        List<Map<String, Object>> tbhldata = busMonthlycumulativedataMapper.manualIndexMonthlyData(tbhlmanualIndexMonthlyDatamap);
        List<Map<String, Object>> ljhkdata = new ArrayList<>();
        if (hkSegmentIdsone != null && hkSegmentIdsone.size() > 0) {
            //下面查询区县整体均值不区分时间
            Map<String, Object> ljhkmanualIndexMonthlyDatamap = new HashMap<>();
            ljhkmanualIndexMonthlyDatamap.put("DataType", "5");
            ljhkmanualIndexMonthlyDatamap.put("beginTime", nowDataTime);
            ljhkmanualIndexMonthlyDatamap.put("endTime", nowDataTime);
            ljhkmanualIndexMonthlyDatamap.put("SegmentIDs", hkSegmentIdsone);
            ljhkmanualIndexMonthlyDatamap.put("datatype", "allCountyCode");//根据区划和因子分组查询
            //湖库均值数据
            ljhkdata = busMonthlycumulativedataMapper.manualIndexMonthlyData(ljhkmanualIndexMonthlyDatamap);

        }
        Map<String, Object> ljhlmanualIndexMonthlyDatamap = new HashMap<>();
        ljhlmanualIndexMonthlyDatamap.put("DataType", "5");
        ljhlmanualIndexMonthlyDatamap.put("beginTime", nowDataTime);
        ljhlmanualIndexMonthlyDatamap.put("endTime", nowDataTime);
        ljhlmanualIndexMonthlyDatamap.put("SegmentIDs", hlSegmentIdsone);
        ljhlmanualIndexMonthlyDatamap.put("datatype", "allCountyCode");//根据区划和因子分组查询
        //河流均值数据
        List<Map<String, Object>> ljhldata = busMonthlycumulativedataMapper.manualIndexMonthlyData(ljhlmanualIndexMonthlyDatamap);

        //同比数据
        //湖库均值数据
        List<Map<String, Object>> ljtbhkdata = new ArrayList<>();
        if (hkSegmentIdsone != null && hkSegmentIdsone.size() > 0) {
            Map<String, Object> ljtbhkmanualIndexMonthlyDatamap = new HashMap<>();
            ljtbhkmanualIndexMonthlyDatamap.put("DataType", "5");
            ljtbhkmanualIndexMonthlyDatamap.put("beginTime", tbDataTime);
            ljtbhkmanualIndexMonthlyDatamap.put("endTime", tbDataTime);
            ljtbhkmanualIndexMonthlyDatamap.put("SegmentIDs", hkSegmentIdsone);
            ljtbhkmanualIndexMonthlyDatamap.put("datatype", "allCountyCode");//根据区划和因子分组查询
            ljtbhkdata = busMonthlycumulativedataMapper.manualIndexMonthlyData(ljtbhkmanualIndexMonthlyDatamap);

        }
        Map<String, Object> ljtbhlmanualIndexMonthlyDatamap = new HashMap<>();
        ljtbhlmanualIndexMonthlyDatamap.put("DataType", "5");
        ljtbhlmanualIndexMonthlyDatamap.put("beginTime", tbDataTime);
        ljtbhlmanualIndexMonthlyDatamap.put("endTime", tbDataTime);
        ljtbhlmanualIndexMonthlyDatamap.put("SegmentIDs", hlSegmentIdsone);
        ljtbhlmanualIndexMonthlyDatamap.put("datatype", "allCountyCode");//根据区划和因子分组查询
        //河流均值数据
        List<Map<String, Object>> ljtbhldata = busMonthlycumulativedataMapper.manualIndexMonthlyData(ljtbhlmanualIndexMonthlyDatamap);

        //获取对应id的每个区划不通数据类型的数量
        List<Map<String, Object>> segmentCountysl = (List<Map<String, Object>>) stringObjectMap.get("segmentCountysl");
        List<Map<String, Object>> tbsegmentCountysl = (List<Map<String, Object>>) stringObjectMap.get("tbsegmentCountysl");

        List<Map<String, Object>> segmentCountyslall = (List<Map<String, Object>>) stringObjectMap.get("segmentCountyslall");
        List<Map<String, Object>> tbsegmentCountyslall = (List<Map<String, Object>>) stringObjectMap.get("tbsegmentCountyslall");

        //计算整体市级的
        Map<String, Object> mapdatashi = new HashMap<>();
        Object sementname = map.get("sementname");
        if(sementname!=null&&"1".equals(sementname)){
            mapdatashi.put("riverName", "高平市");
            mapdatashi.put("riverID", "140581");
        }else if(sementname!=null&&"2".equals(sementname)){
            mapdatashi.put("segmentName", "高平市");
            mapdatashi.put("segmentID", "140581");
        }else {
            mapdatashi.put("county", "高平市");
            mapdatashi.put("countyCode", "140581");
        }
        mapdatashi.put("changeranking", "");
        mapdatashi.put("completed", "true");
        mapdatashi.put("waterQualityIndexranking", "");
        //分组判断，stream流
        //hkCountyCodedata.
        Map<String, List<Map<String, Object>>> ljhkitemdata =
                ljhkdata.stream().collect(
                        Collectors.groupingBy(item -> item.get("ItemCode").toString())
                );
        Map<String, List<Map<String, Object>>> ljhlitemdata =
                ljhldata.stream().collect(
                        Collectors.groupingBy(item -> item.get("ItemCode").toString())
                );
        Map<String, List<Map<String, Object>>> ljtbhkitemdata =
                ljtbhkdata.stream().collect(
                        Collectors.groupingBy(item -> item.get("ItemCode").toString())
                );
        Map<String, List<Map<String, Object>>> ljtbhlitemdata =
                ljtbhldata.stream().collect(
                        Collectors.groupingBy(item -> item.get("ItemCode").toString())
                );

        Map<String, List<Map<String, Object>>> hkitemdata =
                hkdata.stream().collect(
                        Collectors.groupingBy(item -> item.get("ItemCode").toString())
                );
        Map<String, List<Map<String, Object>>> hlitemdata =
                hldata.stream().collect(
                        Collectors.groupingBy(item -> item.get("ItemCode").toString())
                );
        Map<String, List<Map<String, Object>>> tbhkitemdata =
                tbhkdata.stream().collect(
                        Collectors.groupingBy(item -> item.get("ItemCode").toString())
                );
        Map<String, List<Map<String, Object>>> tbhlitemdata =
                tbhldata.stream().collect(
                        Collectors.groupingBy(item -> item.get("ItemCode").toString())
                );
        //根据对应区划处理对应断面id 得到断面id 和断面id数量
        int hksize = 0;
        int hlsize = 0;
        int tbhksize = 0;
        int tbhlsize = 0;
        //cityCodes
        if (cityCodes != null && cityCodes.size() > 0) {
            for (String data : cityCodes) {
                //获取对应区划进行 对区划不同断面数据相加
                if (segmentCountyslall != null && segmentCountyslall.size() > 0) {
                    for (Map<String, Object> datasl : segmentCountyslall) {
                        Object sl = datasl.get("sl");//数量
                        Object countyCode = datasl.get("CountyCode");//区划编码
                        Object segmentCategory = datasl.get("SegmentCategory");//断面类型 1是河流 2湖库
                        Object county = datasl.get("County");//区划名称

                        if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                            if (countyCode != null && !"".equals(countyCode)) {
                                if (data.equals(String.valueOf(countyCode))) {
                                    hlsize = hlsize + Integer.valueOf(String.valueOf(sl));
                                }
                            }
                        }
                        if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                            if (countyCode != null && !"".equals(countyCode)) {
                                if (data.equals(String.valueOf(countyCode))) {
                                    hksize = hksize + Integer.valueOf(String.valueOf(sl));
                                }
                            }
                        }
                    }


                }
                if (tbsegmentCountyslall != null && tbsegmentCountyslall.size() > 0) {
                    for (Map<String, Object> datasl : tbsegmentCountyslall) {
                        Object sl = datasl.get("sl");//数量
                        Object countyCode = datasl.get("CountyCode");//区划编码
                        Object segmentCategory = datasl.get("SegmentCategory");//断面类型 1是河流 2湖库
                        Object county = datasl.get("County");//区划名称
                        Object SampleDates = datasl.get("SampleDates");//时间
                        if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                            /*if (tbhlsize < Integer.valueOf(String.valueOf(sl))) {
                                tbhlsize = Integer.valueOf(String.valueOf(sl));
                            }*/
                            if (countyCode != null && !"".equals(countyCode)) {
                                if (data.equals(String.valueOf(countyCode))) {
                                    tbhlsize = tbhlsize + Integer.valueOf(String.valueOf(sl));
                                }
                            }
                        }
                        if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                            /*if (tbhksize < Integer.valueOf(String.valueOf(sl))) {
                                tbhksize = Integer.valueOf(String.valueOf(sl));
                            }*/
                            if (countyCode != null && !"".equals(countyCode)) {
                                if (data.equals(String.valueOf(countyCode))) {
                                    tbhksize = tbhksize + Integer.valueOf(String.valueOf(sl));
                                }
                            }
                        }
                    }


                }
            }
        }



        if (ItemIsRiverEvalute != null && ItemIsRiverEvalute.size() > 0) {
            String allhl = "0";
            String allhk = "0";
            String alltbhl = "0";
            String alltbhk = "0";
            //不累计月份的均值总值数据
            List<String> allavghl = new ArrayList<>();
            List<String> allavghk = new ArrayList<>();
            List<String> allavgtbhl = new ArrayList<>();
            List<String> allavgtbhk = new ArrayList<>();
            for (Map<String, Object> Itemdata : ItemIsRiverEvalute) {
                Object id = Itemdata.get("ID");//获取因子编码
                Object CNName = Itemdata.get("CNName");//获取因子
                //获取修约的标准值
                String roundingOffstandardValue = "0";
                if (hlroundingOffmaps != null && hlroundingOffmaps.size() > 0) {
                    for (Map<String, Object> data : hlroundingOffmaps) {
                        Object standardValue = data.get("StandardValue");//标准值
                        Object itemCodedata = data.get("ItemCode");//因子编码
                        if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                            roundingOffstandardValue = String.valueOf(standardValue);
                        }
                    }
                }
                //获取计算水质指数的标准值
                String indexstandardValue = "0";
                if (hlindexmaps != null && hlindexmaps.size() > 0) {
                    for (Map<String, Object> data : hlindexmaps) {
                        Object standardValue = data.get("StandardValue");//标准值
                        Object itemCodedata = data.get("ItemCode");//因子编码
                        if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                            indexstandardValue = String.valueOf(standardValue);
                        }
                    }
                }

                //获取修约的标准值
                String hkroundingOffstandardValue = "0";
                if (hkroundingOffmaps != null && hkroundingOffmaps.size() > 0) {
                    for (Map<String, Object> data : hkroundingOffmaps) {
                        Object standardValue = data.get("StandardValue");//标准值
                        Object itemCodedata = data.get("ItemCode");//因子编码
                        if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                            hkroundingOffstandardValue = String.valueOf(standardValue);
                        }
                    }
                }
                //获取计算水质指数的标准值
                String hkindexstandardValue = "0";
                if (hkindexmaps != null && hkindexmaps.size() > 0) {
                    for (Map<String, Object> data : hkindexmaps) {
                        Object standardValue = data.get("StandardValue");//标准值
                        Object itemCodedata = data.get("ItemCode");//因子编码
                        if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                            hkindexstandardValue = String.valueOf(standardValue);
                        }
                    }
                }
                List<Map<String, Object>> hkmaps = ljhkitemdata.get(id);
                List<Map<String, Object>> hlmaps = ljhlitemdata.get(id);
                List<Map<String, Object>> tbhkmaps = ljtbhkitemdata.get(id);
                List<Map<String, Object>> tbhlmaps = ljtbhlitemdata.get(id);
                List<String> avghl = new ArrayList<>();
                List<String> avghk = new ArrayList<>();
                List<String> avgtbhl = new ArrayList<>();
                List<String> avgtbhk = new ArrayList<>();
                if (hkmaps != null && hkmaps.size() > 0) {
                    for (Map<String, Object> hkmapsdata : hkmaps) {
                        Object effectiveValues = hkmapsdata.get("EffectiveValue");
                        String effectiveValue = null;
                        //判断是否科学计算法，如果是就进行转换
                        boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                        if (scientificNotation) {
                            BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                            String effectiveValuesdatas = bigDecimal.toPlainString();
                            effectiveValue = effectiveValuesdatas;
                        } else {
                            effectiveValue = String.valueOf(effectiveValues);
                        }
                        Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                        //   Object SampleDates = hkmapsdata.get("SampleDates");
                        if (effectiveValue != null && !"".equals(effectiveValue)) {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("2")) {
                                avghk.add(String.valueOf(effectiveValue));
                            }
                        }
                    }
                }
                if (hlmaps != null && hlmaps.size() > 0) {
                    for (Map<String, Object> hkmapsdata : hlmaps) {
                        Object effectiveValues = hkmapsdata.get("EffectiveValue");
                        Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                        //  Object SampleDates = hkmapsdata.get("SampleDates");
                        String effectiveValue = null;
                        //判断是否科学计算法，如果是就进行转换
                        boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                        if (scientificNotation) {
                            BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                            String effectiveValuesdatas = bigDecimal.toPlainString();
                            effectiveValue = effectiveValuesdatas;
                        } else {
                            effectiveValue = String.valueOf(effectiveValues);
                        }
                        if (effectiveValue != null && !"".equals(effectiveValue)) {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("1")) {
                                avghl.add(String.valueOf(effectiveValue));
                            }
                        }
                    }
                }
                if (tbhkmaps != null && tbhkmaps.size() > 0) {
                    for (Map<String, Object> hkmapsdata : tbhkmaps) {
                        Object effectiveValues = hkmapsdata.get("EffectiveValue");
                        String effectiveValue = null;
                        //判断是否科学计算法，如果是就进行转换
                        boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                        if (scientificNotation) {
                            BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                            String effectiveValuesdatas = bigDecimal.toPlainString();
                            effectiveValue = effectiveValuesdatas;
                        } else {
                            effectiveValue = String.valueOf(effectiveValues);
                        }
                        Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                        //  Object SampleDates = hkmapsdata.get("SampleDates");
                        if (effectiveValue != null && !"".equals(effectiveValue)) {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("2")) {
                                avgtbhk.add(String.valueOf(effectiveValue));
                            }
                        }
                    }
                }
                if (tbhlmaps != null && tbhlmaps.size() > 0) {
                    for (Map<String, Object> hkmapsdata : tbhlmaps) {
                        Object effectiveValues = hkmapsdata.get("EffectiveValue");
                        String effectiveValue = null;
                        //判断是否科学计算法，如果是就进行转换
                        boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                        if (scientificNotation) {
                            BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                            String effectiveValuesdatas = bigDecimal.toPlainString();
                            effectiveValue = effectiveValuesdatas;
                        } else {
                            effectiveValue = String.valueOf(effectiveValues);
                        }
                        Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                        //Object SampleDates = hkmapsdata.get("SampleDates");
                        if (effectiveValue != null && !"".equals(effectiveValue)) {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("1")) {
                                avgtbhl.add(String.valueOf(effectiveValue));
                            }
                        }
                    }
                }
                //计算月份的水质指数
                if (CNName != null && !"".equals(CNName)) {
                    if (avghl != null && avghl.size() > 0) {
                        String dataValue = SegmentFormula.avgdata(avghl);
                        //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                        Map maplistData = this.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(id), "", "1", "", "", String.valueOf(dataValue));
                        if (maplistData != null && maplistData.size() > 0) {
                            Object v = maplistData.get("_V"); //修约后的值
                            Object in = maplistData.get("_IN");//单个因子的指数
                            if (in != null && !"".equals(in)) {
                                //数据计算总和得到河流/湖库/断面指数总和
                                allavghl.add(String.valueOf(in));
                            }
                        }
                    }
                    if (avghk != null && avghk.size() > 0) {
                        String dataValue = SegmentFormula.avgdata(avghk);
                        //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                        Map maplistData = this.itemDataINV(hkindexstandardValue, hkroundingOffstandardValue, String.valueOf(id), "", "2", "", "", String.valueOf(dataValue));
                        if (maplistData != null && maplistData.size() > 0) {
                            Object v = maplistData.get("_V"); //修约后的值
                            Object in = maplistData.get("_IN");//单个因子的指数
                            if (in != null && !"".equals(in)) {
                                //数据计算总和得到河流/湖库/断面指数总和
                                allavghk.add(String.valueOf(in));
                            }
                        }
                    }
                    if (avgtbhl != null && avgtbhl.size() > 0) {
                        String dataValue = SegmentFormula.avgdata(avgtbhl);
                        //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                        Map maplistData = this.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(id), "", "1", "", "", String.valueOf(dataValue));
                        if (maplistData != null && maplistData.size() > 0) {
                            Object v = maplistData.get("_V"); //修约后的值
                            Object in = maplistData.get("_IN");//单个因子的指数
                            if (in != null && !"".equals(in)) {
                                //数据计算总和得到河流/湖库/断面指数总和
                                allavgtbhl.add(String.valueOf(in));
                            }
                        }
                    }
                    if (avgtbhk != null && avgtbhk.size() > 0) {
                        String dataValue = SegmentFormula.avgdata(avgtbhk);
                        //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                        Map maplistData = this.itemDataINV(hkindexstandardValue, hkroundingOffstandardValue, String.valueOf(id), "", "2", "", "", String.valueOf(dataValue));
                        if (maplistData != null && maplistData.size() > 0) {
                            Object v = maplistData.get("_V"); //修约后的值
                            Object in = maplistData.get("_IN");//单个因子的指数
                            if (in != null && !"".equals(in)) {
                                //数据计算总和得到河流/湖库/断面指数总和
                                allavgtbhk.add(String.valueOf(in));
                            }
                        }
                    }

                }
            }

            //调用完工具类后所有水质指数进行相加总和数据
            if (allavghl != null && allavghl.size() > 0) {
                String dataValue = segmentFormula.noriverWaterQualityIndex(allavghl);
                allhl = dataValue;
            }
            if (allavghk != null && allavghk.size() > 0) {
                String dataValue = segmentFormula.noriverWaterQualityIndex(allavghk);
                allhk = dataValue;
            }
            //hlIndex 河流水质指数, hlsize 河流数量, hkIndex 湖库水质指数, hksize 湖库数量
            String index = segmentFormula.countyIndex(allhl, hlsize, allhk, hksize);
            if (Double.valueOf(index) > 0) {
                mapdatashi.put("waterQualityIndex", Double.valueOf(index));
            } else {
                mapdatashi.put("waterQualityIndex", null);
            }

            if (allavgtbhl != null && allavgtbhl.size() > 0) {
                String dataValue = segmentFormula.noriverWaterQualityIndex(allavgtbhl);
                alltbhl = dataValue;
            }
            if (allavgtbhk != null && allavgtbhk.size() > 0) {
                String dataValue = segmentFormula.noriverWaterQualityIndex(allavgtbhk);
                alltbhk = dataValue;
            }
            //hlIndex 河流水质指数, hlsize 河流数量, hkIndex 湖库水质指数, hksize 湖库数量
            String tbindex = segmentFormula.countyIndex(alltbhl, tbhlsize, alltbhk, tbhksize);
            if (Double.valueOf(tbindex) > 0) {
                mapdatashi.put("tbwaterQualityIndex", Double.valueOf(tbindex));
            } else {
                mapdatashi.put("tbwaterQualityIndex", null);
            }
            //计算变换率 （年达标率-上年达标率）/上年达标率
            if (index != null && tbindex != null && Double.valueOf(index) > 0 && Double.valueOf(tbindex) > 0 && !"0".equals(String.valueOf(index)) && !"0".equals(String.valueOf(tbindex))) {
                Double v = Double.valueOf(index) - Double.valueOf(tbindex);
                Double v1 = v / Double.valueOf(tbindex) * 100;
                mapdatashi.put("change", Double.valueOf(format2.format(v1)));
            } else {
                mapdatashi.put("change", null);
            }
        }
        //当期月的
        if (monthall != null && monthall.size() > 0) {
            for (String monthalldata : monthall) {
                if (ItemIsRiverEvalute != null && ItemIsRiverEvalute.size() > 0) {
                    String allhl = "0";
                    String allhk = "0";
                    int hksizes = 0; //湖库断面id数量
                    int hlsizes = 0; //河流断面id数量
                    if (segmentCountysl != null && segmentCountysl.size() > 0) {
                        for (Map<String, Object> datasl : segmentCountysl) {
                            Object sl = datasl.get("sl");//数量
                            Object countyCode = datasl.get("CountyCode");//区划编码
                            Object segmentCategory = datasl.get("SegmentCategory");//断面类型 1是河流 2湖库
                            Object county = datasl.get("County");//区划名称
                            Object SampleDates = datasl.get("SampleDates");//监测时间
                            if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                                if (SampleDates != null && SampleDates.equals(monthalldata)) {
                                    hlsizes = Integer.valueOf(String.valueOf(sl));
                                }
                            }
                            if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                                if (SampleDates != null && SampleDates.equals(monthalldata)) {
                                    hksizes = Integer.valueOf(String.valueOf(sl));
                                }
                            }
                        }
                    }

                    //不累计月份的均值总值数据
                    List<String> allavghl = new ArrayList<>();
                    List<String> allavghk = new ArrayList<>();
                    for (Map<String, Object> Itemdata : ItemIsRiverEvalute) {
                        Object id = Itemdata.get("ID");//获取因子编码
                        Object CNName = Itemdata.get("CNName");//获取因子
                        //获取修约的标准值
                        String roundingOffstandardValue = "0";
                        if (hlroundingOffmaps != null && hlroundingOffmaps.size() > 0) {
                            for (Map<String, Object> data : hlroundingOffmaps) {
                                Object standardValue = data.get("StandardValue");//标准值
                                Object itemCodedata = data.get("ItemCode");//因子编码
                                if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                    roundingOffstandardValue = String.valueOf(standardValue);
                                }
                            }
                        }
                        //获取计算水质指数的标准值
                        String indexstandardValue = "0";
                        if (hlindexmaps != null && hlindexmaps.size() > 0) {
                            for (Map<String, Object> data : hlindexmaps) {
                                Object standardValue = data.get("StandardValue");//标准值
                                Object itemCodedata = data.get("ItemCode");//因子编码
                                if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                    indexstandardValue = String.valueOf(standardValue);
                                }
                            }
                        }
                        //获取修约的标准值
                        String hkroundingOffstandardValue = "0";
                        if (hkroundingOffmaps != null && hkroundingOffmaps.size() > 0) {
                            for (Map<String, Object> data : hkroundingOffmaps) {
                                Object standardValue = data.get("StandardValue");//标准值
                                Object itemCodedata = data.get("ItemCode");//因子编码
                                if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                    hkroundingOffstandardValue = String.valueOf(standardValue);
                                }
                            }
                        }
                        //获取计算水质指数的标准值
                        String hkindexstandardValue = "0";
                        if (hkindexmaps != null && hkindexmaps.size() > 0) {
                            for (Map<String, Object> data : hkindexmaps) {
                                Object standardValue = data.get("StandardValue");//标准值
                                Object itemCodedata = data.get("ItemCode");//因子编码
                                if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                    hkindexstandardValue = String.valueOf(standardValue);
                                }
                            }
                        }
                        List<Map<String, Object>> hkmaps = hkitemdata.get(id);
                        List<Map<String, Object>> hlmaps = hlitemdata.get(id);
                        List<String> avghl = new ArrayList<>();
                        List<String> avghk = new ArrayList<>();
                        if (hkmaps != null && hkmaps.size() > 0) {
                            // monthalldata
                            //分组判断，stream流
                            Map<String, List<Map<String, Object>>> sunmapsSegmentID =
                                    hkmaps.stream().collect(
                                            Collectors.groupingBy(item -> item.get("SampleDate").toString())
                                    );
                            List<Map<String, Object>> monthalldatalist = sunmapsSegmentID.get(monthalldata);
                            if (monthalldatalist != null && monthalldatalist.size() > 0) {
                                for (Map<String, Object> hkmapsdata : monthalldatalist) {
                                    Object effectiveValues = hkmapsdata.get("EffectiveValue");
                                    String effectiveValue = null;
                                    //判断是否科学计算法，如果是就进行转换
                                    boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                                    if (scientificNotation) {
                                        BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                                        String effectiveValuesdatas = bigDecimal.toPlainString();
                                        effectiveValue = effectiveValuesdatas;
                                    } else {
                                        effectiveValue = String.valueOf(effectiveValues);
                                    }
                                    Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                                    Object SampleDates = hkmapsdata.get("SampleDate");
                                    if (SampleDates != null && SampleDates.equals(monthalldata) && effectiveValue != null && !"".equals(effectiveValue)) {
                                        if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("2")) {
                                            avghk.add(String.valueOf(effectiveValue));
                                        }
                                    }
                                }
                            }

                        }
                        if (hlmaps != null && hlmaps.size() > 0) {
                            // monthalldata
                            //分组判断，stream流
                            Map<String, List<Map<String, Object>>> sunmapsSegmentID =
                                    hlmaps.stream().collect(
                                            Collectors.groupingBy(item -> item.get("SampleDate").toString())
                                    );
                            List<Map<String, Object>> monthalldatalist = sunmapsSegmentID.get(monthalldata);
                            if (monthalldatalist != null && monthalldatalist.size() > 0) {
                                for (Map<String, Object> hkmapsdata : monthalldatalist) {
                                    Object effectiveValues = hkmapsdata.get("EffectiveValue");
                                    String effectiveValue = null;
                                    //判断是否科学计算法，如果是就进行转换
                                    boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                                    if (scientificNotation) {
                                        BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                                        String effectiveValuesdatas = bigDecimal.toPlainString();
                                        effectiveValue = effectiveValuesdatas;
                                    } else {
                                        effectiveValue = String.valueOf(effectiveValues);
                                    }
                                    Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                                    Object SampleDates = hkmapsdata.get("SampleDate");
                                    if (SampleDates != null && SampleDates.equals(monthalldata) && effectiveValue != null && !"".equals(effectiveValue)) {
                                        if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("1")) {
                                            avghl.add(String.valueOf(effectiveValue));
                                        }
                                    }
                                }
                            }
                        }

                        //计算月份的水质指数
                        if (CNName != null && !"".equals(CNName)) {
                            if (avghl != null && avghl.size() > 0) {
                                String dataValue = SegmentFormula.avgdata(avghl);
                                //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                                Map maplistData = this.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(id), "", "1", "", "", String.valueOf(dataValue));
                                if (maplistData != null && maplistData.size() > 0) {
                                    Object v = maplistData.get("_V"); //修约后的值
                                    Object in = maplistData.get("_IN");//单个因子的指数
                                    if (in != null && !"".equals(in)) {
                                        //数据计算总和得到河流/湖库/断面指数总和
                                        allavghl.add(String.valueOf(in));
                                    }
                                }
                            }
                            if (avghk != null && avghk.size() > 0) {
                                String dataValue = segmentFormula.avgdata(avghk);
                                //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                                Map maplistData = this.itemDataINV(hkindexstandardValue, hkroundingOffstandardValue, String.valueOf(id), "", "2", "", "", String.valueOf(dataValue));
                                if (maplistData != null && maplistData.size() > 0) {
                                    Object v = maplistData.get("_V"); //修约后的值
                                    Object in = maplistData.get("_IN");//单个因子的指数
                                    if (in != null && !"".equals(in)) {
                                        //数据计算总和得到河流/湖库/断面指数总和
                                        allavghk.add(String.valueOf(in));
                                    }
                                }
                            }

                        }
                    }

                    //调用完工具类后所有水质指数进行相加总和数据
                    if (allavghl != null && allavghl.size() > 0) {
                        String dataValue = segmentFormula.noriverWaterQualityIndex(allavghl);
                        allhl = dataValue;
                    }
                    if (allavghk != null && allavghk.size() > 0) {
                        String dataValue = segmentFormula.noriverWaterQualityIndex(allavghk);
                        allhk = dataValue;
                    }
                    //hlIndex 河流水质指数, hlsize 河流数量, hkIndex 湖库水质指数, hksize 湖库数量
                    String index = segmentFormula.countyIndex(allhl, hlsize, allhk, hksize);
                    SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM");
                    Calendar tbcalendar = Calendar.getInstance();
                    try {
                        tbcalendar.setTime(dfs.parse(String.valueOf(monthalldata)));
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    int tbmonth = tbcalendar.get(Calendar.MONTH);
                    int monthi = tbmonth + 1;
                    if (Double.valueOf(index) > 0) {
                        mapdatashi.put("waterQualityIndex" + monthi, Double.valueOf(index));
                    } else {
                        mapdatashi.put("waterQualityIndex" + monthi, null);
                    }


                }
            }
        }
        //判断是否需要同比数据
        if (whetherYOY != null && whetherYOY.equals("1")) {
            for (String monthalldata : tbmonthall) {
                if (ItemIsRiverEvalute != null && ItemIsRiverEvalute.size() > 0) {
                    String alltbhl = "0";
                    String alltbhk = "0";
                    int tbhksizes = 0; //湖库断面id数量
                    int tbhlsizes = 0; //河流断面id数量
                    if (tbsegmentCountysl != null && tbsegmentCountysl.size() > 0) {
                        for (Map<String, Object> datasl : tbsegmentCountysl) {
                            Object sl = datasl.get("sl");//数量
                            Object countyCode = datasl.get("CountyCode");//区划编码
                            Object segmentCategory = datasl.get("SegmentCategory");//断面类型 1是河流 2湖库
                            Object county = datasl.get("County");//区划名称
                            Object SampleDates = datasl.get("SampleDates");//监测时间
                            if (segmentCategory != null && String.valueOf(segmentCategory).equals("1")) {
                                if (SampleDates != null && SampleDates.equals(monthalldata)) {
                                    tbhlsizes = Integer.valueOf(String.valueOf(sl));
                                }
                            }
                            if (segmentCategory != null && String.valueOf(segmentCategory).equals("2")) {
                                if (SampleDates != null && SampleDates.equals(monthalldata)) {
                                    tbhksizes = Integer.valueOf(String.valueOf(sl));
                                }
                            }
                        }

                    }
                    //不累计月份的均值总值数据
                    List<String> allavgtbhl = new ArrayList<>();
                    List<String> allavgtbhk = new ArrayList<>();
                    for (Map<String, Object> Itemdata : ItemIsRiverEvalute) {
                        Object id = Itemdata.get("ID");//获取因子编码
                        Object CNName = Itemdata.get("CNName");//获取因子
                        //获取修约的标准值
                        String roundingOffstandardValue = "0";
                        if (hlroundingOffmaps != null && hlroundingOffmaps.size() > 0) {
                            for (Map<String, Object> data : hlroundingOffmaps) {
                                Object standardValue = data.get("StandardValue");//标准值
                                Object itemCodedata = data.get("ItemCode");//因子编码
                                if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                    roundingOffstandardValue = String.valueOf(standardValue);
                                }
                            }
                        }
                        //获取计算水质指数的标准值
                        String indexstandardValue = "0";
                        if (hlindexmaps != null && hlindexmaps.size() > 0) {
                            for (Map<String, Object> data : hlindexmaps) {
                                Object standardValue = data.get("StandardValue");//标准值
                                Object itemCodedata = data.get("ItemCode");//因子编码
                                if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                    indexstandardValue = String.valueOf(standardValue);
                                }
                            }
                        }
                        //获取修约的标准值
                        String hkroundingOffstandardValue = "0";
                        if (hkroundingOffmaps != null && hkroundingOffmaps.size() > 0) {
                            for (Map<String, Object> data : hkroundingOffmaps) {
                                Object standardValue = data.get("StandardValue");//标准值
                                Object itemCodedata = data.get("ItemCode");//因子编码
                                if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                    hkroundingOffstandardValue = String.valueOf(standardValue);
                                }
                            }
                        }
                        //获取计算水质指数的标准值
                        String hkindexstandardValue = "0";
                        if (hkindexmaps != null && hkindexmaps.size() > 0) {
                            for (Map<String, Object> data : hkindexmaps) {
                                Object standardValue = data.get("StandardValue");//标准值
                                Object itemCodedata = data.get("ItemCode");//因子编码
                                if (id != null && !"".equals(id) && itemCodedata.equals(id)) {
                                    hkindexstandardValue = String.valueOf(standardValue);
                                }
                            }
                        }
                        List<Map<String, Object>> tbhkmaps = tbhkitemdata.get(id);
                        List<Map<String, Object>> tbhlmaps = tbhlitemdata.get(id);
                        List<String> avgtbhl = new ArrayList<>();
                        List<String> avgtbhk = new ArrayList<>();
                        if (tbhkmaps != null && tbhkmaps.size() > 0) {
                            for (Map<String, Object> hkmapsdata : tbhkmaps) {
                                Object effectiveValues = hkmapsdata.get("EffectiveValue");
                                String effectiveValue = null;
                                //判断是否科学计算法，如果是就进行转换
                                boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                                if (scientificNotation) {
                                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                                    String effectiveValuesdatas = bigDecimal.toPlainString();
                                    effectiveValue = effectiveValuesdatas;
                                } else {
                                    effectiveValue = String.valueOf(effectiveValues);
                                }
                                Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                                Object SampleDates = hkmapsdata.get("SampleDate");
                                if (SampleDates != null && SampleDates.equals(monthalldata) && effectiveValue != null && !"".equals(effectiveValue)) {
                                    if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("2")) {
                                        avgtbhk.add(String.valueOf(effectiveValue));
                                    }
                                }
                            }
                        }
                        if (tbhlmaps != null && tbhlmaps.size() > 0) {
                            for (Map<String, Object> hkmapsdata : tbhlmaps) {
                                Object effectiveValues = hkmapsdata.get("EffectiveValue");
                                String effectiveValue = null;
                                //判断是否科学计算法，如果是就进行转换
                                boolean scientificNotation = StringUtils.isScientificNotation(String.valueOf(effectiveValues));
                                if (scientificNotation) {
                                    BigDecimal bigDecimal = new BigDecimal(String.valueOf(effectiveValues));
                                    String effectiveValuesdatas = bigDecimal.toPlainString();
                                    effectiveValue = effectiveValuesdatas;
                                } else {
                                    effectiveValue = String.valueOf(effectiveValues);
                                }
                                Object SegmentCategory = hkmapsdata.get("SegmentCategory");
                                Object SampleDates = hkmapsdata.get("SampleDate");
                                if (SampleDates != null && SampleDates.equals(monthalldata) && effectiveValue != null && !"".equals(effectiveValue)) {
                                    if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("1")) {
                                        avgtbhl.add(String.valueOf(effectiveValue));
                                    }
                                }
                            }
                        }
                        //计算月份的水质指数
                        if (CNName != null && !"".equals(CNName)) {
                            if (avgtbhl != null && avgtbhl.size() > 0) {
                                String dataValue = SegmentFormula.avgdata(avgtbhl);
                                //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                                Map maplistData = this.itemDataINV(indexstandardValue, roundingOffstandardValue, String.valueOf(id), "", "1", "", "", String.valueOf(dataValue));
                                if (maplistData != null && maplistData.size() > 0) {
                                    Object v = maplistData.get("_V"); //修约后的值
                                    Object in = maplistData.get("_IN");//单个因子的指数
                                    if (in != null && !"".equals(in)) {
                                        //数据计算总和得到河流/湖库/断面指数总和
                                        allavgtbhl.add(String.valueOf(in));
                                    }
                                }
                            }
                            if (avgtbhk != null && avgtbhk.size() > 0) {
                                String dataValue = SegmentFormula.avgdata(avgtbhk);
                                //indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值
                                Map maplistData = this.itemDataINV(hkindexstandardValue, hkroundingOffstandardValue, String.valueOf(id), "", "2", "", "", String.valueOf(dataValue));
                                if (maplistData != null && maplistData.size() > 0) {
                                    Object v = maplistData.get("_V"); //修约后的值
                                    Object in = maplistData.get("_IN");//单个因子的指数
                                    if (in != null && !"".equals(in)) {
                                        //数据计算总和得到河流/湖库/断面指数总和
                                        allavgtbhk.add(String.valueOf(in));
                                    }
                                }
                            }

                        }
                    }

                    //调用完工具类后所有水质指数进行相加总和数据
                    if (allavgtbhl != null && allavgtbhl.size() > 0) {
                        String dataValue = segmentFormula.noriverWaterQualityIndex(allavgtbhl);
                        alltbhl = dataValue;
                    }
                    if (allavgtbhk != null && allavgtbhk.size() > 0) {
                        String dataValue = segmentFormula.noriverWaterQualityIndex(allavgtbhk);
                        alltbhk = dataValue;
                    }
                    //hlIndex 河流水质指数, hlsize 河流数量, hkIndex 湖库水质指数, hksize 湖库数量
                    String tbindex = segmentFormula.countyIndex(alltbhl, tbhlsize, alltbhk, tbhksize);
                    SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM");
                    Calendar tbcalendar = Calendar.getInstance();
                    try {
                        tbcalendar.setTime(dfs.parse(String.valueOf(monthalldata)));
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    int tbmonth = tbcalendar.get(Calendar.MONTH);
                    int monthi = tbmonth + 1;
                    if (Double.valueOf(tbindex) > 0) {
                        mapdatashi.put("tbwaterQualityIndex" + monthi, Double.valueOf(tbindex));
                    } else {
                        mapdatashi.put("tbwaterQualityIndex" + monthi, null);
                    }

                }
            }
        }

        return mapdatashi;
    }

    /**
     * 查询水质指数和修约后的值
     * @Param [indexstandardLimits 计算水质指数的标准值  roundingOffstandardLimits 计算均值修约的数据 itemCode 监测编码 itemName 监测值名称, type 断面类型, beginTime 开始时间, endTime 结束时间, itemdata 监测值]
     **/
    public Map itemDataINV(String indexstandardLimits, String roundingOffstandardLimits, String itemCode, String itemName, String type, String beginTime, String endTime, String itemdata) {
        //调用工具类判断是否需要/2
        itemdata = segmentFormula.verificationOfMonitoringValues(itemdata);
        Map<String, Object> maplistData = new HashMap<>();//存放断面处理过的数据值
        //判断导入监测只是否为空和-1
        if (itemdata != null && !"".equals(itemdata) && !"-1".equals(itemdata)) {
            //在计算水质指数之前先把平均值进行修约
            String aDouble1 = segmentFormula.roundingOffs(Double.valueOf(itemdata), itemCode, String.valueOf(roundingOffstandardLimits), 0.0, "1", "", "");
            String aDouble = segmentFormula.waterQualityIndexOfIndividualIndicatorss(Double.valueOf(aDouble1), itemCode, Double.valueOf(roundingOffstandardLimits), Double.valueOf(indexstandardLimits), type, beginTime, endTime, "1");
            Map mapdat = new HashMap();
            mapdat.put("ItemCode", itemCode);
            mapdat.put("bussinessCategoryCode", "CBN");
            maplistData.put("_V", aDouble1);
            maplistData.put("_IN", aDouble);
            maplistData.put("itemCode", itemCode);
        } else {
            maplistData.put("_V", null);
            maplistData.put("_IN", null);
            maplistData.put("itemCode", itemCode);
        }
        return maplistData;
    }

    /**
     * 返回对应的断面id/开始结束时间
     * dataTime, 查询时间
     * segmentId, 断面id 多个以逗号隔开
     * assessTypeCode, 考核类型 多个以逗号隔开
     **/
    public Map<String, Object> SegmentIdsksjsdatatime(Map<String, Object> map) {
        //存放返回数据
        Map<String, Object> mapdatalist = new HashMap<>();
        Object dataTime = map.get("dataTime");//时间
        List<String> assessTypeCodes = (List<String>) map.get("assessTypeCodes");//考核编码 0国考 1省考 2市考
        List<String> segmentIds = (List<String>) map.get("segmentIds");//断面id
        //先获取传入时间的年份 直接从一月开始为开始时间
        SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM");
        Calendar calendar = Calendar.getInstance();
        try {
            calendar.setTime(dfs.parse(String.valueOf(dataTime)));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int year = calendar.get(Calendar.YEAR);
        String beginTime = year + "-01";
        //需要添加同比数据
        String tbksData = null;
        String tbjsData = null;
        //调用工具类获取同比时间
        Map<String, Object> stringObjectMap = DateUtils.OnTheSameMonthRatio(beginTime, String.valueOf(dataTime), "yyyy-mm");
        if (stringObjectMap != null && stringObjectMap.size() > 0) {
            tbksData = (String) stringObjectMap.get("tbksData");
            tbjsData = (String) stringObjectMap.get("tbjsData");
        }
        //查询是否参与计算的因子
        Map<String, Object> wqBasItemIDIsRiverEvalutemap = new HashMap<>();
        wqBasItemIDIsRiverEvalutemap.put("IsRiverEvalute", "1");
        List<Map<String, Object>> ItemIsRiverEvalute = publicToolsMapper.wqBasItemIDIsRiverEvalute(wqBasItemIDIsRiverEvalutemap);
        //筛选需要的断面id
        List<String> SegmentIds = new ArrayList<>();
        List<String> hkSegmentIdsone = new ArrayList<>();
        List<String> tbhkSegmentIdsone = new ArrayList<>();
        List<String> hlSegmentIdsone = new ArrayList<>();
        List<String> tbhlSegmentIdsone = new ArrayList<>();
        List<String> CityCodes = new ArrayList<>();
        List<String> RiverIDs = new ArrayList<>();
        if (segmentIds != null && segmentIds.size() > 0 && assessTypeCodes != null && assessTypeCodes.size() > 0) {
            Map<String, Object> AssessTypeCodesegmentmap = new HashMap<>();
            AssessTypeCodesegmentmap.put("segmentType", "IsManual");
            AssessTypeCodesegmentmap.put("segmentTypes", "IsManualIsDrink");
            AssessTypeCodesegmentmap.put("Segmenttype", "RiverSegment");
            AssessTypeCodesegmentmap.put("segmentIds", segmentIds);//传入断面id不为空传入进行查询
            //判断考核类型不为空就传入
            if (assessTypeCodes != null && assessTypeCodes.size() > 0) {
                AssessTypeCodesegmentmap.put("Type", "CountyCode");
                AssessTypeCodesegmentmap.put("AssessTypeCodes", assessTypeCodes);
            }
            List<Map<String, Object>> maps = publicToolsMapper.AssessTypeCodesegments(AssessTypeCodesegmentmap);
            AssessTypeCodesegmentmap.put("dataTime", tbjsData);
            List<Map<String, Object>> tbmaps = publicToolsMapper.tbAssessTypeCodesegments(AssessTypeCodesegmentmap);
            if (maps != null && maps.size() > 0) {
                for (Map<String, Object> data : maps) {
                    Object id = data.get("SegmentID");//断面id
                    Object SegmentCategory = data.get("SegmentCategory");//断面分类（1河流/2湖库/3地下水）
                    Object RiverID = data.get("RiverID");//河流id
                    // Object CountyCode = data.get("CountyCode");//区划编码
                    Object CountyCode = data.get("AssessTownCode");//区划编码
                    if (id != null && !"".equals(id)) {
                        boolean contains = SegmentIds.contains(id);
                        boolean hkonecontains = hkSegmentIdsone.contains(id);
                        boolean hlonecontains = hlSegmentIdsone.contains(id);
                        boolean RiverIDcontains = true;
                        if (hlonecontains) {

                        } else {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("1")) {
                                hlSegmentIdsone.add(String.valueOf(id));
                            }
                        }
                        if (hkonecontains) {

                        } else {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("2")) {
                                hkSegmentIdsone.add(String.valueOf(id));
                            }
                        }
                        if (RiverID != null && !"".equals(RiverID)) {
                            RiverIDcontains = RiverIDs.contains(RiverID);
                        }
                        boolean Citycontains = true;
                        if (CountyCode != null && !"".equals(CountyCode)) {
                            Citycontains = CityCodes.contains(CountyCode);
                        }

                        if (RiverIDcontains) {

                        } else {
                            if (RiverID != null && !"".equals(RiverID)) {
                                RiverIDs.add(String.valueOf(RiverID));
                            }
                        }
                        if (Citycontains) {

                        } else {
                            if (CountyCode != null && !"".equals(CountyCode)) {
                                CityCodes.add(String.valueOf(CountyCode));
                            }
                        }
                        if (contains) {

                        } else {
                            SegmentIds.add(String.valueOf(id));
                        }
                    }
                }
            }

            if (tbmaps != null && tbmaps.size() > 0) {
                for (Map<String, Object> data : tbmaps) {
                    Object id = data.get("SegmentID");//断面id
                    Object SegmentCategory = data.get("SegmentCategory");//断面分类（1河流/2湖库/3地下水）
                    Object RiverID = data.get("RiverID");//河流id
                    //Object CountyCode = data.get("CountyCode");//区划编码
                    Object CountyCode = data.get("AssessTownCode");//区划编码
                    if (id != null && !"".equals(id)) {
                        boolean contains = SegmentIds.contains(id);
                        boolean hkonecontains = hkSegmentIdsone.contains(id);
                        boolean hlonecontains = hlSegmentIdsone.contains(id);
                        boolean RiverIDcontains = true;
                        if (hlonecontains) {

                        } else {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("1")) {
                                hlSegmentIdsone.add(String.valueOf(id));
                            }
                        }
                        if (hkonecontains) {

                        } else {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("2")) {
                                hkSegmentIdsone.add(String.valueOf(id));
                            }
                        }
                        if (RiverID != null && !"".equals(RiverID)) {
                            RiverIDcontains = RiverIDs.contains(RiverID);
                        }
                        boolean Citycontains = true;
                        if (CountyCode != null && !"".equals(CountyCode)) {
                            Citycontains = CityCodes.contains(CountyCode);
                        }

                        if (RiverIDcontains) {

                        } else {
                            if (RiverID != null && !"".equals(RiverID)) {
                                RiverIDs.add(String.valueOf(RiverID));
                            }
                        }
                        if (Citycontains) {

                        } else {
                            if (CountyCode != null && !"".equals(CountyCode)) {
                                CityCodes.add(String.valueOf(CountyCode));
                            }
                        }
                        if (contains) {

                        } else {
                            SegmentIds.add(String.valueOf(id));
                        }
                    }
                }
            }
        } else {
            //如果默认断面id为空 考核类型为空就默认获取全部的断面id
            Map<String, Object> WqBasSegmentNameAllmap = new HashMap<>();
            WqBasSegmentNameAllmap.put("segmentType", "IsManual");
            WqBasSegmentNameAllmap.put("segmentTypes", "IsManualIsDrink");
            WqBasSegmentNameAllmap.put("Segmenttype", "RiverSegment");
            WqBasSegmentNameAllmap.put("segmentIds", segmentIds);
            List<Map> list = publicToolsMapper.WqBasSegmentNameAll(WqBasSegmentNameAllmap);
            if (list != null && list.size() > 0) {
                for (Map data : list) {
                    Object id = data.get("ID");//断面id
                    Object SegmentCategory = data.get("SegmentCategory");//断面分类（1河流/2湖库/3地下水）
                    Object RiverID = data.get("ThirdRiverSystemId");//河流id
                    Object CountyCode = data.get("CountyCode");//区划编码
                    if (id != null && !"".equals(id)) {
                        boolean contains = SegmentIds.contains(id);
                        boolean RiverIDcontains = true;
                        boolean hkonecontains = hkSegmentIdsone.contains(id);
                        boolean hlonecontains = hlSegmentIdsone.contains(id);
                        if (hlonecontains) {

                        } else {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("1")) {
                                hlSegmentIdsone.add(String.valueOf(id));
                            }

                        }
                        if (hkonecontains) {

                        } else {
                            if (SegmentCategory != null && String.valueOf(SegmentCategory).equals("2")) {
                                hkSegmentIdsone.add(String.valueOf(id));
                            }

                        }
                        if (RiverID != null && !"".equals(RiverID)) {
                            RiverIDcontains = RiverIDs.contains(RiverID);
                        }
                        boolean Citycontains = true;
                        if (CountyCode != null && !"".equals(CountyCode)) {
                            Citycontains = CityCodes.contains(CountyCode);
                        }

                        if (RiverIDcontains) {

                        } else {
                            if (RiverID != null && !"".equals(RiverID)) {
                                RiverIDs.add(String.valueOf(RiverID));
                            }
                        }
                        if (Citycontains) {

                        } else {
                            if (CountyCode != null && !"".equals(CountyCode)) {
                                CityCodes.add(String.valueOf(CountyCode));
                            }
                        }
                        if (contains) {

                        } else {
                            SegmentIds.add(String.valueOf(id));
                        }

                    }
                }
            }
        }
        //获取传入时间所有月份
        List<String> monthall = DateUtils.getMonthall(beginTime, String.valueOf(dataTime));


        // SegmentIds  beginTime  dataTime
        Map<String, Object> segmentCountyslmap = new HashMap<>();
        segmentCountyslmap.put("SegmentIds", SegmentIds);
        segmentCountyslmap.put("beginTime", beginTime);
        segmentCountyslmap.put("endTime", dataTime);
        List<Map<String, Object>> maps = publicToolsMapper.segmentCountysl(segmentCountyslmap);
        // tbksData  tbjsData
        Map<String, Object> tbsegmentCountyslmap = new HashMap<>();
        tbsegmentCountyslmap.put("SegmentIds", SegmentIds);
        tbsegmentCountyslmap.put("beginTime", tbksData);
        tbsegmentCountyslmap.put("endTime", tbjsData);
        List<Map<String, Object>> tbmaps = publicToolsMapper.segmentCountysl(tbsegmentCountyslmap);


        Map<String, Object> allsegmentCountyslmap = new HashMap<>();
        allsegmentCountyslmap.put("SegmentIds", SegmentIds);
        allsegmentCountyslmap.put("beginTime", beginTime);
        allsegmentCountyslmap.put("endTime", dataTime);
        List<Map<String, Object>> allmaps = publicToolsMapper.segmentCountyslall(allsegmentCountyslmap);
        // tbksData  tbjsData
        Map<String, Object> alltbsegmentCountyslmap = new HashMap<>();
        alltbsegmentCountyslmap.put("SegmentIds", SegmentIds);
        alltbsegmentCountyslmap.put("beginTime", tbksData);
        alltbsegmentCountyslmap.put("endTime", tbjsData);
        List<Map<String, Object>> alltbmaps = publicToolsMapper.segmentCountyslall(alltbsegmentCountyslmap);
        List<String> tbmonthall = DateUtils.getMonthall(tbksData, tbjsData);
        mapdatalist.put("segmentCountysl", maps);
        mapdatalist.put("segmentCountyslall", allmaps);
        mapdatalist.put("tbsegmentCountyslall", alltbmaps);
        mapdatalist.put("tbsegmentCountysl", tbmaps);
        mapdatalist.put("beginTime", beginTime);
        mapdatalist.put("ItemIsRiverEvalute", ItemIsRiverEvalute);
        mapdatalist.put("SegmentIds", SegmentIds);
        mapdatalist.put("RiverIDs", RiverIDs);
        mapdatalist.put("monthall", monthall);
        mapdatalist.put("tbjsData", tbjsData);
        mapdatalist.put("tbksData", tbksData);
        mapdatalist.put("tbmonthall", tbmonthall);
        mapdatalist.put("hkSegmentIdsone", hkSegmentIdsone);
        mapdatalist.put("hlSegmentIdsone", hlSegmentIdsone);
        mapdatalist.put("CityCodes", CityCodes);

        return mapdatalist;
    }

}
